mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
feat: 使用实体类构建 QueryWrapper 时,可以使用实体类中属性标记的 TypeHandler 对值进行处理,关闭 https://gitee.com/mybatis-flex/mybatis-flex/issues/IAANT6。
This commit is contained in:
parent
8447d5e4c2
commit
0df1ea103b
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2025, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* Copyright (c) 2022-2024, Mybatis-Flex (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -1025,15 +1025,31 @@ public class TableInfo {
|
||||
} else if (operator == SqlOperator.LIKE_RIGHT || operator == SqlOperator.NOT_LIKE_RIGHT) {
|
||||
value = "%" + value;
|
||||
}
|
||||
queryWrapper.and(QueryCondition.create(queryColumn, operator, value));
|
||||
queryWrapper.and(QueryCondition.create(queryColumn, operator, buildSqlArg(column, value)));
|
||||
} else {
|
||||
queryWrapper.and(queryColumn.eq(value));
|
||||
queryWrapper.and(queryColumn.eq(buildSqlArg(column, value)));
|
||||
}
|
||||
}
|
||||
});
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
private Object buildSqlArg(String column, Object value) {
|
||||
ColumnInfo columnInfo = columnInfoMapping.get(column);
|
||||
// 给定的列名在实体类中没有对应的字段
|
||||
if (columnInfo == null) {
|
||||
return value;
|
||||
}
|
||||
// 如果给定的列名在实体类中有对应的字段
|
||||
// 则使用实体类中属性标记的 @Column(typeHandler = ...) 类型处理器处理参数
|
||||
// 调用 TypeHandler#setParameter 为 PreparedStatement 设置值
|
||||
TypeHandler<?> typeHandler = columnInfo.buildTypeHandler(null);
|
||||
if (typeHandler != null) {
|
||||
return new TypeHandlerObject(typeHandler, value, columnInfo.getJdbcType());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getKeyProperties() {
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
for (IdInfo value : primaryKeyList) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user