67,512
社区成员
发帖
与我相关
我的任务
分享
public class Bean2Map {
public static HashMap format(TbAccount in){
HashMap map=new HashMap();
map.put(MyKey.TBACCOUNT.NAME, in.getName());
map.put(MyKey.TBACCOUNT.ACCOUNT, in.getAccount());
map.put(MyKey.TBACCOUNT.PASSWORD, in.getPassword());
map.put(MyKey.TBACCOUNT.SEX, in.getSex());
return map;
}
public static HashMap format(TbDish in){
HashMap map=new HashMap();
map.put(MyKey.TBDISH.NAME, in.getName());
map.put(MyKey.TBDISH.KIND, in.getKind().getName());
map.put(MyKey.TBDISH.PRICE, in.getPrice()+"");
map.put(MyKey.TBDISH.ID, in.getDishId().toString());
return map;
}
public static HashMap format(TbRestaurant in){
HashMap map=new HashMap();
map.put(MyKey.TBRESTAURANT.ID, in.getRestaurantId().toString());
return map;
}
public static HashMap format(Object in){
HashMap map=new HashMap();
map.put("ob", "ob");
return map;
}
public static List<HashMap> formatDishList(List<TbDish> in){
List<HashMap> list=new ArrayList<HashMap>();
for (TbDish dish : in) {
list.add(format(dish));
}
return list;
}
public static <T> List<HashMap> format(List<T> in){
List<HashMap> list=new ArrayList<HashMap>();
for (T item : in) {
list.add(format(item));
}
return list;
}
}
for (T item : in) {
if (item intanceof xxx) {format((xxx)item);} //只能强行转换为相应的类型
else format(item);
}