//业务实体类 public class YXX extends Model<YXX>{ public static final YXX dao = new YXX().dao(); private String ET; private String IN; private String UN; private String RE; private String ENE; 省略getter setter... } public class BDDataServiceController extends Controller { public void YXX () { Page<YXX> page = YXX.dao.paginate(1, 100, "select * from YXX",""); //数据表里有二行数据,但打印的实体类中的属性全部是NULL System.err.println(page.getList().get(0)); } } 我跟踪到ModelBuilder类中的public <T> List<T> build(ResultSet rs, Class<? extends Model> modelClass) throws SQLException, InstantiationException, IllegalAccessException 方法,发现 ... while (rs.next()) { Model<?> ar = modelClass.newInstance(); Map<String, Object> attrs = ar._getAttrs(); for (int i=1; i<=columnCount; i++) { Object value; if (types[i] < Types.BLOB) { value = rs.getObject(i); } else { if (types[i] == Types.CLOB) { value = handleClob(rs.getClob(i)); } else if (types[i] == Types.NCLOB) { value = handleClob(rs.getNClob(i)); } else if (types[i] == Types.BLOB) { value = handleBlob(rs.getBlob(i)); } else { value = rs.getObject(i); } } attrs.put(labelNames[i], value); //打断点在这里确实取到了数据表中的数据并put到attrs中 } result.add((T)ar); //直接把ar放到list里,没有把值赋值到ar的属性中。 } return result; result结果全部都是YXX[ET=null,IN=null,UN=null,RE=null,ENE=null]
请问是我API用错了吗?上面看上去就是把
Model<?> ar = modelClass.newInstance();
新建对象放到LIST里直接返回了? 谢谢