Difference between @ param in spring and @ param in mybatis, @ parammybatis
/*** Query whether the specified user and enterprise are associated with a configured role * @ param businessId memberId * @ return */int selectRoleCount (@ Param ("businessId") Integer businessId, @ Param ("memberId") Long memberId );
/*** Query whether the specified user and enterprise are associated with a configured role * @ param businessId memberId * @ return */int selectRoleCount (@ Param ("businessId") Integer businessId, @ Param ("memberId") Long memberId );
On the surface, there is no difference between the two types, but they are different when used in xml files. @ param in Spring needs to reference variables in xml as follows:
<select id="selectRoleCount" resultType="java.lang.Integer" >select count(tbm.id) from t_business_member_relation tbm where tbm.business_id = #{0,jdbcType=INTEGER} and tbm.member_id = #{1,jdbcType=INTEGER} and tbm.role_business_id is not null</select>
The value is based on the order of parameters, and starts from 0. In mybatis @ param, variables are referenced as follows in xml.
<select id="selectRoleCount" resultType="java.lang.Integer" > select count(tbm.id) from t_business_member_relation tbm where tbm.business_id = #{businessId,jdbcType=INTEGER} and tbm.member_id = #{memberId,jdbcType=INTEGER} and tbm.role_business_id is not null </select>
It is referenced by the parameter name.
Note: If the Mapper. java file references Spring
org.springframework.data.repository.query.Param;
However, if mybatis is used in Mapper. xml, the following error occurs:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'businessId' not found. Available parameters are [1, 0, param1, param2]
As follows:
Therefore, you must pay attention to the consistency between @ param reference and usage.