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);方法值会填充不过去呢?
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);方法值会填充不过去呢?
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 对象呢?前辈提示下。。