在dao层接口中
导包不同:
import org.apache.ibatis.annotations.Param; //Mybatis包
import org.springframework.data.repository.query.Param; //spring包
用法一致:
int selectRoleCount(@Param("businessId") Integer businessId,@Param("memberId") Long memberId);
在xml中
Spring中的@param在xml是根据参数的顺序来取值的,并且从0开始:
<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>
mybatis中的@param在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>