org.apache.ibatis.binding.BindingException

1、异常提示:

  org.apache.ibatis.binding.BindingException: Mapper method 'com.artup.dao.WorksDao.selectWorksIsCropCompletedById attempted to return null from a method with a primitive return type (byte).


2、原因:在使用 MyBatis 时,写了个查询语句,其返回值设置为了 byte 类型,当从数据库中能够查询到数据时,不会报错;当前查询不到数据时则会抛出此异常,是由于 null 不能够直接转换成 byte 类型导致的,我们可以将返回类型设置为对象 Byte,从而能够接收值为 null 的情况。



3、解决办法:

  3.1 将所有查询到的数据的值都设置为数字;

    或者
  3.2 将返回的类型由 byte 改成 Byte 从而能够接收 null 类型的值。