Skip to content

Commit

Permalink
优化自动填充时字段类型转换功能
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyning committed Mar 22, 2023
1 parent 3583b5f commit 48aea5d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mpp的lambda方式(1.7.0中使用@com.MPP@col)<br>
<dependency>
<groupId>com.github.jeffreyning</groupId>
<artifactId>mybatisplus-plus</artifactId>
<version>1.7.3-RELEASE</version>
<version>1.7.4-RELEASE</version>
</dependency>
````

Expand Down Expand Up @@ -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有冲突
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.jeffreyning</groupId>
<artifactId>mybatisplus-plus</artifactId>
<version>1.7.3-RELEASE</version>
<version>1.7.4-RELEASE</version>
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 48aea5d

Please sign in to comment.