Spring boot 报错 1:Expected one result (or null) to be returned by selectOne(), but found: 9"

接口报错: 

"timestamp": "2019-05-01 16:09:11",
  "status": 500,
  "error": "Internal Server Error",
  "message": "nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 9",
  "trace": "org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 9\r\n\tat 

后台: 

摆明:期望查到的数据是一条记录或者是空,但是查到了9条;

问题:检查自己的mapper.xml 中的查询语句是否未加限制。

 

缺少where语句

添加后完成查询。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3 是一个异常错误,它意味着在使用selectOne()方法时,期望只返回一个结果或者返回null,但实际上找到了3个结果。 解决这个问题的方法有两种: 1. 使用selectList()方法代替selectOne()方法。selectList()方法可以返回多个结果,这样即使查询到多个结果,你也可以通过代码来处理。 2. 优化SQL语句,确保只返回一个结果。可以通过添加合适的查询条件或者使用其他查询方式来限制查询结果的数量,以满足期望的需求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ nested exception is org.apache.ibatis.exceptions.TooManyResultsException:Expected one result](https://blog.csdn.net/m0_61682705/article/details/125029333)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 4](https://blog.csdn.net/monicateacat/article/details/131961098)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值