/** 获取缓存实体表信息 */ public EntityTable getEntityTable(Class<?> claxx, boolean needPK) { EntityTable table = getEntityTable(claxx.getName()); if (table == null) { table = new EntityTable(); putEntityTable(claxx.getName(), table); table.claxx = claxx; table.name = TableUtil.getTableName(claxx); table.pmap = new LinkedHashMap<String, Property>(); List<Field> fields = FieldUtil.getAllDeclaredFields(claxx); // Field[] fields = claxx.getDeclaredFields(); for (Field f : fields) { if (FieldUtil.isInvalid(f)) { continue; } Property p = new Property(); p.field = f; // 获取列名,每个属性都有,没有注解默认取属性名 Column col = f.getAnnotation(Column.class); if (col != null) { p.column = col.value(); } else { p.column = f.getName(); } // 主键判断 PrimaryKey key = f.getAnnotation(PrimaryKey.class); if (key != null) { // 主键不加入属性Map table.key = new com.litesuits.orm.db.model.PrimaryKey(p, key.value()); // 主键为系统分配,必须为Long型 if (table.key.isAssignedBySystem()) { if (table.key.field.getType() != Long.class && table.key.field.getType() != long.class) { throw new RuntimeException( PrimaryKey.AssignType.AUTO_INCREMENT + "要求主键属性必须是Long型( the primary key should be Long or long...)\n 提示:把你的主键设置为Long或long型"); } } } else { // ORM handle Mapping mapping = f.getAnnotation(Mapping.class); if (mapping != null) { table.addMapping(new MapProperty(p, mapping.value())); } else { table.pmap.put(p.column, p); } } } } if (needPK && table.key == null) { throw new RuntimeException( "你必须设置主键(you must set the primary key...)\n 提示:在对象的属性上加PrimaryKey注解来设置主键。"); } return table; }