Bootstrap

Error updating database. Cause: java.lang.IllegalStateException: Type handler was null on parameter

com.xx.*.mapper.xx.XXXMapper.deleteBatchIds出现
Error updating database. Cause: java.lang.IllegalStateException: Type handler was null on parameter mapping for property '__frch_item_0'. It was either not specified and/or could not be found for the javaType (com.xx.dao.model.x.xxx) : jdbcType (null) combination.
数据库
在这里插入图片描述

测试分析:

    @Test
    void deleteBatch(){
        ArrayList<Student> studentArrayList = new ArrayList<>();
        Student student1 =  new Student();
        Student student2 =  new Student();
        student1.setStudentId(1L);
        student2.setStudentId(2L);
        studentArrayList.add(student1);
        studentArrayList.add(student2);
        studentService.removeByIds(studentArrayList);
    }

于是乎
在这里插入图片描述
在这里插入图片描述
可以看到批量删除要求的是实现了序列化的idList集合,当我们传入studentArrayList能逃过编译异常,因为student实现了序列化,但是并不满足id集合,所以删除时会出现类型转化错误。

还有个要注意的地方,再用mybatisplus对数据库进行操作时字段定义不要用int,建议用Integer,int默认值为0,例如以下代码

	@TableField("age")
	private int studentAge;

  	@Test
    void updateBatchById(){
        ArrayList<Student> studentArrayList = new ArrayList<>();
        Student student1 =  new Student();
        Student student2 =  new Student();
        student1.setStudentId(1L);
        student2.setStudentId(2L);
        student2.setStudentSex(1);
        student1.setStudentSex(1);
        studentArrayList.add(student1);
        studentArrayList.add(student2);
        studentService.updateBatchById(studentArrayList);
    }

console:
JDBC Connection [HikariProxyConnection@1413117445 wrapping com.mysql.cj.jdbc.ConnectionImpl@33997e07] will be managed by Spring
==>  Preparing: UPDATE t_student2 SET sex=?, age=? WHERE id=? AND deleted=0 
==> Parameters: 1(Integer), 0(Integer), 1(Long)
==> Parameters: 1(Integer), 0(Integer), 2(Long)
;