如果吧session.getAttribute()转换成String类型或者int类型

版权声明:不可转载,盗文必究 https://blog.csdn.net/weixin_43815507/article/details/89450037

【错误例子】

String s=session.getAttribute("key");

【正确写法】

String s=session.getAttribute("key").toString();

【转换成int类型】

String s=session.getAttribute("key").toString();
int n=Integer.parseInt(s);

或者

String s=session.getAttribute("key").toString();
int n=Integer.valueOf()(s);

具体parsetInt和valueOf的区别请看其他教程

猜你喜欢

转载自blog.csdn.net/weixin_43815507/article/details/89450037
今日推荐