MybatisPlus采用updateById更新数据抛异常:Cause: org.apache.ibatis.type.TypeException:Error setting null for parameter #1 with JdbcType OTHER
情景:Spring-SpringMVC-Mybatisplus,采用MybatisPlus的selectOne方法查询出数据,此数据某个字段值为null,修改了该数据除了该空值的其他几个字段,之后采用MybatisPlus的updateById方法更新,抛出异常
例如:
Account account = service.selectOne(xxx);//采用MybatisPlus的selectOne方法查询数据,其中字段Phone值为null
String mail = request.getParameter(xxx);//需要修改的参数
account.setMail(mail);
boolean flag = service.updateById(account);//采用MybatisPlus的updateById方法,抛出异常
解决:
1、新建mybatis-config.xml,在配置数据库的xml中引入该xml
mybatis-config.xml
配置数据xml部分
2、不需要新建xml文件,直接在配置数据库的xml中配置
相关内容
MybatisPlus采用updateById无法更新空值或者null:https://mp.csdn.net/postedit/98588479