报错 :类型转换问题 java.lang.String cannot be cast to java.lang.Integer] with root cause

喜欢ヅ旅行 2023-10-03 12:31 115阅读 0赞

上报错

  1. Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer] with root cause
  2. java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
  3. at com.mhy.day17.service.impl.TShopServiceImpl.eslist(TShopServiceImpl.java:65) ~[classes/:na]
  4. at com.mhy.day17.service.impl.TShopServiceImpl$$FastClassBySpringCGLIB$$1.invoke(<generated>) ~[classes/:na]
  5. at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]

上代码

  1. public PageUtils eslist(Map<String, Object> params) {
  2. Integer page = (Integer) params.get("page")
  3. }

想转成Integer 类型但是报错 说不能转 ,
**

原因 Object必须要先转成String类型才能再转成Integer

**

  1. public PageUtils eslist(Map<String, Object> params) {
  2. String page1 = (String) params.get("page");//Object转String
  3. Integer page= Integer.valueOf(page1);StringInteger
  4. }

成功

发表评论

表情:
评论列表 (有 0 条评论,115人围观)

还没有评论,来说两句吧...

相关阅读