spring中@param和mybatis中@param使用区别
生活随笔
收集整理的這篇文章主要介紹了
spring中@param和mybatis中@param使用区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
從表面上看,兩種并沒有區別,但是在xml文件中使用的時候是有區別的,Spring中的@param在xml需要如下這樣引用變量
<select id="selectRoleCount" resultType="java.lang.Integer" > select count(tbm.id)from t_business_member_relation tbmwhere tbm.business_id = #{0,jdbcType=INTEGER}and tbm.member_id = #{1,jdbcType=INTEGER}and tbm.role_business_id is not null </select>是根據參數的順序來取值的,并且從0開始。而在mybatis @param在xml中則是如下這樣引用變量的
<select id="selectRoleCount" resultType="java.lang.Integer" >select count(tbm.id)from t_business_member_relation tbmwhere tbm.business_id = #{businessId,jdbcType=INTEGER}and tbm.member_id = #{memberId,jdbcType=INTEGER}and tbm.role_business_id is not null</select>是通過參數名來引用的?
注:如果Mapper.java文件中引用的是Spring的
但是Mapper.xml中使用的是mybatis 的用法,那么就會如下的錯誤
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'businessId' not found. Available parameters are [1, 0, param1, param2]?
截圖如下?
?
所以在使用的時候一定要注意@param引用和使用的一致性
最好的方法就是在使用注意引用的是哪個包里面的。
比如 引用的是Mybatis的時候
import org.apache.ibatis.annotations.Param;本文轉載自http://blog.csdn.net/gao36951/article/details/44258217
轉載于:https://www.cnblogs.com/sunxun/p/5530917.html
總結
以上是生活随笔為你收集整理的spring中@param和mybatis中@param使用区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Scrum 项目7.0
- 下一篇: STM8启动分析及IAP