《springboot和mybatis项目使用枚举转换器出现No enum constant及解决方法》


mybatis枚举转换器参见此篇博客。
我们知道写好了枚举转换器以后,可以在xxxMapper.xml中配置handler,如下:

 

也可以在mybatis-config.xml中进行配置,如下:


    	
    

在springboot项目中,第一种方式试了,OK没问题,但是使用第二种方式的时候出现如下错误:


Error attempting to get column 'type' from result set.  Cause: java.lang.IllegalArgumentException: No enum constant com.db.enums.PersonEnum.1

Caused by: java.lang.IllegalArgumentException: No enum constant com.db.enums.PersonEnum.1

说明springboot没有找到枚举转换器,查找了半天,终于找到原因。

springboot项目中需要在application.properties增加如下代码:

mybatis.typeHandlersPackage=com.db.enumhandler

值为枚举处理器所在的包名。

你可能感兴趣的:(java,spring,boot,springboot,mybatis,No,enum,constant,typehandler)