Spring框架和Mybatis中@param的不同及其对应Xml

15 篇文章 0 订阅
6 篇文章 0 订阅
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>


 
  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值