1.
spring中@param
/**
* 查询指定用户和企业关联有没有配置角色
* @param businessId memberId
* @return
*/
int selectRoleCount(@Param("businessId") Integer businessId,@Param("memberId") Long memberId);
2.
Mybatis中@param
/*
*
查询指定用户和企业关联有没有配置角色
* @param businessId memberId
* @return
*/
int selectRoleCount(@Param("businessId") Integer businessId,@Param("memberId") Long memberId);
<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 isnot null
</select>
如上在xml文件中0(作为一个索引值)表示引用第一个@param注释参数businessId,1表示引用第二个@param注释参数memberId。
若使用Mybatis中@param则将0改为businessId,1改为memberId,即直接使用参数名进行引用。
注:如果Mapper.Java文件中引用的是Spring的
org.springframework.data.repository.query.Param;
但是Mapper.xml中使用的是mybatis 的用法,那么就会如下的错误
org.mybatis.spring.MyBatisSystemException:
nested exception is org.apache.ibatis.binding.BindingException: Parameter 'businessI'
<resultMap id="BaseResultMap" type="实体路径"> <id column="id" jdbcType="VARCHAR" property="id"/>//column对应数据库字段,property对应实体属性 <result column="member_id" jdbcType="VARCHAR" property="memberId"/>//jdbcType表示实体属性类型
</resultMap>
<select id="对应dao层方法名" resultMap="BaseResultMap" parameterType="">
//resultMap查询返回类型 parameterType对应传入参数类型 SELECT * FROM register WHERE member_id = #{memberId,jdbcType=VARCHAR} </select>