interface ValueSetter<T> {public void set(T entity, Object v);}interface ValueGetter<T> {public Object get(T entity);}public class BaseHelper<T extends BaseEntity> implements Converter {public static final String ID = "id";public static final String PARENT_ID = "parentId";public static final String UUID = "uuid";public static final String DELETED = "deleted";public static final String DISABLED = "disabled";public static final String CREATE_USER = "createUser";public static final String CREATE_TIME = "createTime";public static final String UPDATE_TIME = "updateTime";public static final String UPDATE_USER = "updateUser";public static final String DATA_VERSION = "dataVersion";public static final String ORDER_NUM = "orderNum";public Map<String, ValueGetter<T>> baseGetterMap() {Map<String, ValueGetter<T>> map = new TreeMap<>();map.put(ID, T::getId);map.put(UUID, T::getUuid);map.put(DISABLED, T::getDisabled);map.put(CREATE_USER, T::getCreateUser);map.put(CREATE_TIME, T::getCreateTime);map.put(UPDATE_TIME, T::getUpdateTime);map.put(UPDATE_USER, T::getUpdateUser);map.put(DATA_VERSION, T::getDataVersion);return map;}public Map<String, ValueSetter<T>> baseSetterMap() {Map<String, ValueSetter<T>> map = new TreeMap<>();map.put(ID, (T e, Object v) -> e.setId(toLong(v)));map.put(UUID, (T e, Object v) -> e.setUuid(toString(v)));map.put(DISABLED, (T e, Object v) -> e.setDisabled(toBoolean(v)));map.put(CREATE_USER, (T e, Object v) -> e.setCreateUser(toLong(v)));map.put(CREATE_TIME, (T e, Object v) -> e.setCreateTime(toDate(v)));map.put(UPDATE_TIME, (T e, Object v) -> e.setUpdateTime(toDate(v)));map.put(UPDATE_USER, (T e, Object v) -> e.setUpdateUser(toLong(v)));map.put(DATA_VERSION, (T e, Object v) -> e.setDataVersion(toLong(v)));return map;}public Map<String, Class<?>> baseFieldTypeInfo() {Map<String, Class<?>> map = new TreeMap<>();map.put(ID, Long.class);map.put(UUID, String.class);map.put(DISABLED, Boolean.class);map.put(CREATE_USER, Long.class);map.put(CREATE_TIME, Date.class);map.put(UPDATE_TIME, Date.class);map.put(UPDATE_USER, Long.class);map.put(DATA_VERSION, Long.class);return map;} }
1 package tech.abcd.core.entity.helper; 2 3 import java.util.*; 4 5 import org.springframework.stereotype.Component; 6 7 import tech.zqxx.common.helper.entity.BaseEntity; 8 import tech.zqxx.common.helper.entity.BaseHelper; 9 import tech.zqxx.common.helper.entity.DomainHelper; 10 import tech.zqxx.common.helper.entity.ValueGetter; 11 import tech.zqxx.common.helper.entity.ValueSetter; 12 import tech.zqxx.core.entity.*; 13 14 /**** 15 * 本代码由生成器生成,请勿修改 16 */ 17 @Component 18 public class SysDeptHelper extends BaseHelper<SysDept> implements DomainHelper<SysDept> { 19 20 // 字段名常量定义 21 public static final String DEPT_NAME = "deptName"; 22 public static final String LEADER = "leader"; 23 public static final String DATA_VERSION = "dataVersion"; 24 public static final String ORDER_NUM = "orderNum"; 25 public static final String UPDATE_USER = "updateUser"; 26 public static final String REMARK = "remark"; 27 public static final String UPDATE_TIME = "updateTime"; 28 public static final String UUID = "uuid"; 29 public static final String PARENT_ID = "parentId"; 30 public static final String CREATE_TIME = "createTime"; 31 public static final String DISABLED = "disabled"; 32 public static final String CREATE_USER = "createUser"; 33 public static final String ID = "id"; 34 35 36 37 @Override 38 public Class<SysDept> getDomainClass() { 39 return SysDept.class; 40 } 41 42 @Override 43 public SysDept create() { 44 return new SysDept(); 45 } 46 47 @Override 48 public Map<String, ValueGetter<SysDept>> getterMap() { 49 Map<String, ValueGetter<SysDept>> map = new HashMap<>(); 50 map.put(DEPT_NAME, SysDept::getDeptName); 51 map.put(LEADER, SysDept::getLeader); 52 map.put(ORDER_NUM, SysDept::getOrderNum); 53 map.put(REMARK, SysDept::getRemark); 54 map.put(PARENT_ID, SysDept::getParentId); 55 map.putAll(baseGetterMap()); 56 return Collections.unmodifiableMap(map); 57 } 58 59 @Override 60 public Map<String, ValueSetter<SysDept>> setterMap() { 61 Map<String, ValueSetter<SysDept>> map = new HashMap<>(); 62 map.put(DEPT_NAME, (entity, v) -> entity.setDeptName(toString(v))); 63 map.put(LEADER, (entity, v) -> entity.setLeader(toLong(v))); 64 map.put(ORDER_NUM, (entity, v) -> entity.setOrderNum(toLong(v))); 65 map.put(REMARK, (entity, v) -> entity.setRemark(toString(v))); 66 map.put(PARENT_ID, (entity, v) -> entity.setParentId(toLong(v))); 67 map.putAll(baseSetterMap()); 68 return Collections.unmodifiableMap(map); 69 } 70 71 @Override 72 public Map<String, Class<? extends BaseEntity>> fieldComponentTypeInfo() { 73 Map<String, Class<? extends BaseEntity>> map = new HashMap<>(); 74 return Collections.unmodifiableMap(map); 75 } 76 77 @Override 78 public Map<String, Class<?>> fieldTypeInfo() { 79 Map<String, Class<?>> map = new HashMap<>(); 80 81 map.put(DEPT_NAME, String.class); 82 map.put(LEADER, Long.class); 83 map.put(ORDER_NUM, Long.class); 84 map.put(REMARK, String.class); 85 map.put(PARENT_ID, Long.class); 86 map.putAll(baseFieldTypeInfo()); 87 return Collections.unmodifiableMap(map); 88 } 89 90 }
看的懂的,自然知道,这段代码解决了什么问题,看不懂的,一头雾水。
