Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ce9dd3

Browse files
committed
去掉UUID和JDBC时的字段类型限制,需要自己保证类型一致。
1 parent e1fb9ef commit 5ce9dd3

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/main/java/com/github/abel533/mapperhelper/EntityHelper.java

+12-18
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public static class EntityColumn {
110110
private boolean uuid = false;
111111
private boolean identity = false;
112112
private String generator;
113+
private String keyProperties;//useGenerator包含多列的时候需要用到
113114
private String orderBy;
114115

115116
public String getProperty() {
@@ -176,6 +177,14 @@ public void setGenerator(String generator) {
176177
this.generator = generator;
177178
}
178179

180+
public String getKeyProperties() {
181+
return keyProperties;
182+
}
183+
184+
public void setKeyProperties(String keyProperties) {
185+
this.keyProperties = keyProperties;
186+
}
187+
179188
public String getOrderBy() {
180189
return orderBy;
181190
}
@@ -423,18 +432,10 @@ public static synchronized void initEntityNameMap(Class<?> entityClass) {
423432
} else if (field.isAnnotationPresent(GeneratedValue.class)) {
424433
GeneratedValue generatedValue = field.getAnnotation(GeneratedValue.class);
425434
if (generatedValue.generator().equals("UUID")) {
426-
if (field.getType().equals(String.class)) {
427-
entityColumn.setUuid(true);
428-
} else {
429-
throw new RuntimeException(field.getName() + " - 该字段@GeneratedValue配置为UUID,但该字段类型不是String");
430-
}
435+
entityColumn.setUuid(true);
431436
} else if (generatedValue.generator().equals("JDBC")) {
432-
if (Number.class.isAssignableFrom(field.getType())) {
433-
entityColumn.setIdentity(true);
434-
entityColumn.setGenerator("JDBC");
435-
} else {
436-
throw new RuntimeException(field.getName() + " - 该字段@GeneratedValue配置为UUID,但该字段类型不是String");
437-
}
437+
entityColumn.setIdentity(true);
438+
entityColumn.setGenerator("JDBC");
438439
} else {
439440
//允许通过generator来设置获取id的sql,例如mysql=CALL IDENTITY(),hsqldb=SELECT SCOPE_IDENTITY()
440441
//允许通过拦截器参数设置公共的generator
@@ -475,13 +476,6 @@ public static synchronized void initEntityNameMap(Class<?> entityClass) {
475476
entityTableMap.put(entityClass, entityTable);
476477
}
477478

478-
public static void main(String[] args) {
479-
System.out.println(camelhumpToUnderline("userName"));
480-
System.out.println(camelhumpToUnderline("userPassWord"));
481-
System.out.println(camelhumpToUnderline("ISO9001"));
482-
System.out.println(camelhumpToUnderline("hello_world"));
483-
}
484-
485479
/**
486480
* 将驼峰风格替换为下划线风格
487481
*/

src/main/java/com/github/abel533/mapperhelper/MapperTemplate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ protected void newSelectKeyMappedStatement(MappedStatement ms, EntityHelper.Enti
394394
Class<?> entityClass = getSelectReturnType(ms);
395395
//defaults
396396
Configuration configuration = ms.getConfiguration();
397-
KeyGenerator keyGenerator = null;
397+
KeyGenerator keyGenerator;
398398
Boolean executeBefore = getBEFORE();
399399
String IDENTITY = (column.getGenerator() == null || column.getGenerator().equals("")) ? getIDENTITY() : column.getGenerator();
400400
if (IDENTITY.equalsIgnoreCase("JDBC")) {

0 commit comments

Comments
 (0)