From 48aea5d65bad4ca6f924572e25de7387ef32d859 Mon Sep 17 00:00:00 2001 From: jeffreyning Date: Wed, 22 Mar 2023 14:00:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8=E5=A1=AB?= =?UTF-8?q?=E5=85=85=E6=97=B6=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++- pom.xml | 2 +- .../mybatisplus/util/ReadValueUtil.java | 52 ++++++++++++++++++- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a0b2b6b..d08e17e 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ mpp的lambda方式(1.7.0中使用@com.MPP@col)
com.github.jeffreyning mybatisplus-plus - 1.7.3-RELEASE + 1.7.4-RELEASE ```` @@ -386,6 +386,9 @@ _启动时日志中有mpp.entityBasePath is null skip scan result map_ _提示java.lang.RuntimeException: not found column for 'xxx'_ 是由于设置了@MppMultiId的字段没有同时设置@TableField(value = "xxx")导致的 +_使用@UpdateFill和@InsertFill自动填充时报错提示Cause: java.lang.IllegalArgumentException: argument type mismatch_ +由于对某些entity中的字段类型没有做转换如LocalDateTime导致自动填充的sql的返回值类型与entity字段类型不相符,mpp1.7.4版本已经解决了此问题,旧版本需修改entity字段类型与sql返回类型一致。 + _如何整合pagehelper插件_ mybatisplus本身有分页常见,如果一定要使用pagehelper插件的话,与原生的mybatisplus有冲突 @@ -403,9 +406,12 @@ mybatisplus本身有分页常见,如果一定要使用pagehelper插件的话 ``` **版本说明** +mybatisplus-plus1.7.4优化自动填充时的字段类型转换功能 +mybatisplus-plus1.7.3兼容mybatisplus3.5.1+ mybatisplus-plus1.7.2支持mpp的多主键@MppMultiId可以和mp的单主键@TableId兼容,同时修饰同一个field mybatisplus-plus1.7.1支持继承多主键entity + **兼容性说明** mybatisplus-plus1.5.0兼容mybatisplus3.3.1(mybatis3.5.3)到最新版mybatisplus3.4.2(mybatis3.5.6) diff --git a/pom.xml b/pom.xml index 2532fba..e25215e 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.github.jeffreyning mybatisplus-plus - 1.7.3-RELEASE + 1.7.4-RELEASE com.baomidou diff --git a/src/main/java/com/github/jeffreyning/mybatisplus/util/ReadValueUtil.java b/src/main/java/com/github/jeffreyning/mybatisplus/util/ReadValueUtil.java index 8342ea1..aef4106 100644 --- a/src/main/java/com/github/jeffreyning/mybatisplus/util/ReadValueUtil.java +++ b/src/main/java/com/github/jeffreyning/mybatisplus/util/ReadValueUtil.java @@ -3,10 +3,18 @@ import org.apache.ibatis.type.*; import java.math.BigDecimal; +import java.math.BigInteger; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; +import java.time.*; +import java.util.Date; - +/** + * 自动填充时sql返回值与entity字段类型转换 + * @author ninghao + * @version 1.7.4 + */ public class ReadValueUtil { public static Object readValue(ResultSet rs, Class fieldType) throws SQLException { @@ -34,6 +42,48 @@ public static Object readValue(ResultSet rs, Class fieldType) throws SQLExceptio }else if(fieldType.equals(BigDecimal.class)) { BigDecimalTypeHandler typeHandler=new BigDecimalTypeHandler(); return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(String.class)) { + StringTypeHandler typeHandler=new StringTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(BigInteger.class)) { + BigIntegerTypeHandler typeHandler=new BigIntegerTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(Character.class)) { + CharacterTypeHandler typeHandler=new CharacterTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(Date.class)) { + DateTypeHandler typeHandler=new DateTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(LocalDateTime.class)) { + LocalDateTimeTypeHandler typeHandler=new LocalDateTimeTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(LocalDate.class)) { + LocalDateTypeHandler typeHandler=new LocalDateTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(LocalTime.class)) { + LocalTimeTypeHandler typeHandler=new LocalTimeTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(Month.class)) { + MonthTypeHandler typeHandler=new MonthTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(java.sql.Date.class)) { + SqlDateTypeHandler typeHandler=new SqlDateTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(java.sql.Timestamp.class)) { + SqlTimestampTypeHandler typeHandler=new SqlTimestampTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(java.sql.Time.class)) { + SqlTimeTypeHandler typeHandler=new SqlTimeTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(YearMonth.class)) { + YearMonthTypeHandler typeHandler=new YearMonthTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(Year.class)) { + YearTypeHandler typeHandler=new YearTypeHandler(); + return typeHandler.getNullableResult(rs,1); + }else if(fieldType.equals(ZonedDateTime.class)) { + ZonedDateTimeTypeHandler typeHandler=new ZonedDateTimeTypeHandler(); + return typeHandler.getNullableResult(rs,1); }else{ return rs.getObject(1); }