TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3
时间: 2023-10-23 08:29:58 浏览: 157
求救!!mybatis Expected one result (or null) to be returned by selectOne(), but found:18
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 ]
阅读全文