request.getAttribute()的数据类型转换问题
生活随笔
收集整理的這篇文章主要介紹了
request.getAttribute()的数据类型转换问题
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
request.getAttribute("")返回的是object類(lèi)型
int amount =(int)request.getAttribute("buyamount");
這種的轉(zhuǎn)換方式一直會(huì)報(bào)錯(cuò),需要強(qiáng)制解封裝:
int amount = Integer.parseInt(request.getAttribute("buyamount").toString());
轉(zhuǎn)float類(lèi)型也是一樣的道理
float money = Float.parseFloat(request.getAttribute("moneyamount").toString());
?
總結(jié)
以上是生活随笔為你收集整理的request.getAttribute()的数据类型转换问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Leetcode--347. 前k个高频
- 下一篇: Leetcode--837. 新21点(