欢迎访问我的网站:www.ifueen.com

Mybatis报错问题

一次项目在使用MyBatis进行高级查询的时候,如果传入的值为空报错:Expected one result (or null) to be returned by selectOne(), but found: 2

Mapper.xml如下:
MyBatis报错:Expected one result (or null) to be returned by selectOne(), but found: 2

不要在意查询的语句,我给出的思路是,如果传进来的name为空,就查询所有,不然就进行模糊查询,但是在name为空和查询出结果有多个的时候,报错:Expected one result (or null) to be returned by selectOne(), but found: 2

网上查了许久,才明白是因为返回类型对应不上

我的Mapper类
MyBatis报错:Expected one result (or null) to be returned by selectOne(), but found: 2
我给出的返回结果是一个实体类,而查询出的结果可能是多条数据,所以对应不上

修改为List集合

MyBatis报错:Expected one result (or null) to be returned by selectOne(), but found: 2

然后运行即可

自己总结了一下,出现这个错误还是因为自己对MyBatis的理解不够深

相关文章:

  • 2022-12-23
  • 2021-06-23
  • 2021-11-06
  • 2021-08-02
  • 2021-05-31
  • 2022-12-23
  • 2021-10-31
  • 2022-01-10
猜你喜欢
  • 2021-08-02
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-09-09
相关资源
相似解决方案