Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Mapper method 'com.icss.hospitalmanagessm.mapper.BookMapper.findNum attempted to return null from a method with a primitive return type (int).
时间: 2024-03-25 22:40:12 浏览: 28
这个错误的原因是在你的 `BookMapper` 接口中的 `findNum` 方法返回类型为 `int`,但是在 SQL 语句执行时返回了 `null`,这违反了 Java 中的基本类型不能为 `null` 的规则,导致了 `BindingException` 异常。
需要将 `findNum` 方法的返回类型改为 `Integer`,并在 SQL 语句执行时,确保返回值不为 `null`,可以通过 `COALESCE` 函数来实现:
```
<select id="findNum" resultType="java.lang.Integer">
SELECT COALESCE(SUM(num), 0) FROM book WHERE book_id = #{bookId}
</select>
```
这样,即使 SQL 语句返回了 `null`,`COALESCE` 函数会将其转换为 0,避免了返回 `null` 导致的异常。同时,将返回类型改为 `Integer`,也允许返回 `null` 值,避免了异常的出现。
相关问题
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
这个错误提示表明在处理请求时出现了问题,具体原因是绑定的语句无效,即找不到对应的语句。这通常是由于MyBatis配置文件中的语句ID与Mapper接口中的方法名不匹配所导致的。可以检查一下Mapper接口中的方法名是否与配置文件中的语句ID一致。如果还是无法解决问题,可以考虑检查一下Mapper接口和XML文件的路径是否正确,或者检查一下是否有其他错误导致了这个问题的出现。
nested exception is org.apache.ibatis.binding.BindingException:
nested exception is org.apache.ibatis.binding.BindingException是MyBatis框架中的异常,表示在执行Mapper接口方法时出现了参数绑定异常。具体的错误信息是"Parameter 'xxx' not found. Available parameters are [xxx, xxx, ...]"。这个异常通常发生在Mapper接口方法的参数与XML映射文件中定义的参数不匹配的情况下。
要解决这个异常,可以从以下几个方面入手:
1. 检查Mapper接口方法的参数名与XML映射文件中的参数名是否一致。确保参数名的一致性可以避免这个异常的出现。
2. 检查Mapper接口方法的参数个数与XML映射文件中定义的参数个数是否一致。如果个数不一致,也会导致参数绑定异常的发生。
3. 在XML映射文件中,可以使用param1、param2等占位符来表示参数的位置,而不是具体的参数名。这样可以避免参数名不一致导致的异常。
总结一下,nested exception is org.apache.ibatis.binding.BindingException表示MyBatis在执行Mapper接口方法时遇到了参数绑定异常。要解决这个问题,需要确保Mapper接口方法的参数与XML映射文件中的参数一致,并检查参数个数是否匹配。如果还是无法解决,可以考虑使用占位符来表示参数位置。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [mybatis异常:nested exception is org.apache.ibatis.binding.BindingException](https://blog.csdn.net/niu1109/article/details/124434791)[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%"]
- *3* [nested exception is org.apache.ibatis.binding.BindingException 解决方式汇总](https://blog.csdn.net/qq_39609993/article/details/128725325)[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 ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)