public MovieTbl fillMovieInfo(DynaBean bean, List movietypelist) {
MovieTbl movie = new MovieTbl();
Iterator<MovietypeTbl> it = movietypelist.iterator();
String typeidstr = "";
while (it.hasNext()) {
Object typeid = bean.get(it.next().getMovietypeId().toString());
if (typeid != null) {
typeidstr += typeid + "|";
}
}
System.out.println(typeidstr);
bean.set("movietypeId", typeidstr);
try {
BeanUtils.copyProperties(movie, bean);
System.out.println(movie.getMovietypeId());
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
movie.setMovietypeId(bean.get("movietypeId").toString());
System.out.println(movie.getMovietypeId());
return movie;
}
这里bean里装的是页面form传过来的数据。 属性的名称也与movie 类的名称一致。。
为什么通过BeanUtils.copyProperties(movie, bean);方法值会填充不过去呢?

解决方案 »

  1.   

    你是说全部填充不了还是有些值,form中的字段表现形式应该是String,如果你的movie中式Date或者别的类型的,自然不会帮助你去类型转换的。
      

  2.   

    populate(Object bean, Map properties) 这个方法试试。
      

  3.   

    是全部不填充。
    BeanUtils.copyProperties(movie, bean); 
    System.out.println(movie.getMovietypeId()); 
    这里打出来是空值
    下面通过set方法可以把值放进去。sysout正常输出
    movie.setMovietypeId(bean.get("movietypeId").toString()); 
    System.out.println(movie.getMovietypeId()); Movie中movietypeId 是String 类型的
    populate(Object bean, Map properties) 
    只知道Dyna 中的存值的方式是按key ,value 形式放的
    那Dyna 对象怎么得到Map 对象呢?前辈提示下。。