From 0df1ea103bedcbd390a1ea3c64c19c50c102c2d4 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Oct 2024 11:42:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E7=B1=BB=E6=9E=84=E5=BB=BA=20QueryWrapper=20=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E4=BD=BF=E7=94=A8=E5=AE=9E=E4=BD=93=E7=B1=BB?= =?UTF-8?q?=E4=B8=AD=E5=B1=9E=E6=80=A7=E6=A0=87=E8=AE=B0=E7=9A=84=20TypeHa?= =?UTF-8?q?ndler=20=E5=AF=B9=E5=80=BC=E8=BF=9B=E8=A1=8C=E5=A4=84=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E5=85=B3=E9=97=AD=20https://gitee.com/mybatis-flex/my?= =?UTF-8?q?batis-flex/issues/IAANT6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mybatisflex/core/table/TableInfo.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java index 07d0987a..49a4cf4b 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2025, Mybatis-Flex (fuhai999@gmail.com). + * Copyright (c) 2022-2024, Mybatis-Flex (fuhai999@gmail.com). *

* 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) {