Jfinal Model的多态性

controller

Model m=new TbBuildWbs();
Class model=(Class) m.getClass();
int res=xxxService.batchUpdate(data,model);//data为json串[{},{}] 

service

public int batchUpdate(String data, Class model) {
    List modelList=new ArrayList();
    JSONArray jsonarr=JSONArray.fromObject(data);
    for (Object object : jsonarr) {
        modelList.add(translateModel(object,model));
    }
    return xxxService.resInt(Db.batchUpdate((List) modelList, modelList.size()));//resint 方法将int[]转为int
}
//将obj转成model实体类
public Model translateModel(Object obj, Class model){
    return FastJson.getJson().parse(obj.toString(), model);
}

你可能感兴趣的:(Jfinal Model的多态性)