mybatis-plus
mybatis-plus copied to clipboard
延迟枚举扫描注册问题
当前使用版本(必填,否则不予处理)
目前版本3.5.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
版本从3.5.0升级到3.5.1以后,xml里面的自定义sql,无法识别到对应的枚举,但是调用mybatis-plus内置方法则可以正常识别枚举,怀疑是“延迟枚举扫描注册”逻辑问题引发的,请问怎么解决这个问题
重现步骤(如果有就写完整)
在xml文件定义sql用到了枚举会报错
报错信息
无法识别枚举类型
最新版测试能识别
mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- UserMapper @author <[email protected]> @since 2022/4/19 13:32 -->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruben.mybatisplusissue.mapper.UserMapper">
<resultMap id="resultMap" type="com.ruben.mybatisplusissue.entity.User">
<id property="id" column="id"/>
<id property="username" column="username"/>
<id property="password" column="password"/>
<id property="gender" column="gender"/>
</resultMap>
<select id="msgSelect" resultMap="resultMap">
select *
from user
where id = #{dto.id}
</select>
</mapper>
实体
package com.ruben.mybatisplusissue.entity;
import java.io.Serializable;
import com.ruben.mybatisplusissue.enumration.GenderEnum;
import lombok.Data;
/**
* @author <[email protected]>
* @since 2022/4/19 13:33
*/
@Data
public class User implements Serializable {
private static final long serialVersionUID = 1335028235832341270L;
private Long id;
private String username;
private String password;
private GenderEnum gender;
}
枚举
package com.ruben.mybatisplusissue.enumration;
/**
* 性别
*
* @author <[email protected]>
* @since 2022/4/20 13:41
*/
public enum GenderEnum {
/**
* 男
*/
MALE,
/**
* 女
*/
FEMALE
}
配置
# 应用名称
spring.application.name=mybatis-plus-issue
# 数据库驱动:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 数据源名称
spring.datasource.name=defaultDataSource
# 数据库连接地址
spring.datasource.url=jdbc:mysql://localhost:3306/xxx?serverTimezone=UTC
# 数据库用户名&密码:
spring.datasource.username=xxx
spring.datasource.password=xxx
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
mybatis-plus.configuration.default-enum-type-handler=org.apache.ibatis.type.EnumOrdinalTypeHandler
我也遇到1楼同样的问题。 楼上的老哥 EnumOrdinalTypeHandler 这种方式是没问题。 但是当枚举类存数据库字段用 @EnumValue的方式就有问题。
最新版还有该问题再提issue