Skip to content

Commit

Permalink
在 Fn 中修改了规则:
Browse files Browse the repository at this point in the history
1. 先区分大小写匹配字段
2. 如果不存在,再忽略大小写进行匹配
  • Loading branch information
abel533 committed Apr 17, 2022
1 parent 7182643 commit 828dcdd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions mapper/src/main/java/io/mybatis/mapper/fn/Fn.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ default String toColumn() {
default Reflections.ClassField toClassField() {
if (!FN_CLASS_FIELD_MAP.containsKey(this)) {
synchronized (this) {
if(!FN_CLASS_FIELD_MAP.containsKey(this)) {
if (!FN_CLASS_FIELD_MAP.containsKey(this)) {
FN_CLASS_FIELD_MAP.put(this, Reflections.fnToFieldName(this));
}
}
Expand All @@ -110,10 +110,14 @@ default EntityColumn toEntityColumn() {
synchronized (this) {
if (!FN_COLUMN_MAP.containsKey(this)) {
Reflections.ClassField classField = toClassField();
EntityColumn entityColumn = EntityFactory.create(classField.getClazz()).columns().stream()
.filter(column -> column.property().equals(classField.getField())).findFirst()
.orElseThrow(() -> new RuntimeException(classField.getField()
+ " does not mark database column field annotations, unable to obtain column information"));
List<EntityColumn> columns = EntityFactory.create(classField.getClazz()).columns();
EntityColumn entityColumn = columns.stream()
// 先区分大小写匹配字段
.filter(column -> column.property().equals(classField.getField())).findFirst()
// 如果不存在,再忽略大小写进行匹配
.orElseGet(() -> columns.stream().filter(column -> column.property().equalsIgnoreCase(classField.getField()))
.findFirst().orElseThrow(() -> new RuntimeException(classField.getField()
+ " does not mark database column field annotations, unable to obtain column information")));
FN_COLUMN_MAP.put(this, entityColumn);
}
}
Expand Down

0 comments on commit 828dcdd

Please sign in to comment.