| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
免费IT实战开发视频教程合集分享千里之行 始于足下
共有 747 人关注过本帖
标题:使用beanutils 封装出错,怎么解决?
只看楼主 加入收藏
米团
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-4-6
结帖率:33.33%
  已结贴   问题点数:10  回复次数:4   
使用beanutils 封装出错,怎么解决?
//c.手动封装product
                Product p = new Product();
                BeanUtils.populate(p, map);
                oi.setProduct(p);

java.lang.IllegalArgumentException: java.lang.ClassCastException@57bf5ee7
    at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1789)
    at com.sun.org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1684)
    at com.sun.org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:1713)
    at com.sun.org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019)
    at com.sun.org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
    at cn.hl.dao.impl.OrderDaoImpl.findMyOrdersByPage(OrderDaoImpl.java:86)
    at cn.hl.service.impl.OrderServiceImpl.findMyOrdersByPage(OrderServiceImpl.java:60)
    at cn.hl.web.servlet.OrderServlet.findMyOrdersByPage(OrderServlet.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at cn.hl.web.servlet.base.BaseServlet.service(BaseServlet.java:21)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at cn.hl.filter.EncodingFilter.doFilter(EncodingFilter.java:34)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:610)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:503)
    at java.lang.Thread.run(Thread.java:619)

2018-06-25 18:04
静水且流深
Rank: 5Rank: 5
等 级:贵宾
威 望:11
帖 子:60
专家分:319
注 册:2017-7-7
  得分:4 
java.lang.IllegalArgumentException: java.lang.ClassCastException@57bf5ee7
    at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1789)
    at com.sun.org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1684)
    at com.sun.org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:1713)
    at com.sun.org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019)
    at com.sun.org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
    at cn.hl.dao.impl.OrderDaoImpl.findMyOrdersByPage(OrderDaoImpl.java:86)
    at cn.hl.service.impl.OrderServiceImpl.findMyOrdersByPage(OrderServiceImpl.java:60)
    at cn.hl.web.servlet.OrderServlet.findMyOrdersByPage(OrderServlet.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)

不过是爱情,又能走多久
2018-06-25 21:47
米团
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-4-6
  得分:0 
回复 2楼 静水且流深
就是上面那三行代码出错的地方,怎么改?
2018-06-25 22:22
疯狂的小a
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:22
帖 子:380
专家分:1662
注 册:2018-2-6
  得分:4 
java.lang.IllegalArgumentException: java.lang.ClassCastException@57bf5ee7
类型转换错误,如果map里面的key和product的属性对应的应该可以封装数据,你把map的打印看一下

假如人生没有梦想,和咸鱼有什么区别!
2018-06-26 21:49
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:101
帖 子:1660
专家分:7215
注 册:2015-3-19
  得分:4 
什么都没看到,还问别人怎么改?
作业吗?

wechat    PrinceThumb
2018-06-26 22:31







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021499 second(s), 8 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved