mybatis注意事项

1.dao层接口 只有一个参数 且没有绑定@Param时

getSectionListByTargetId(String target)

xml test要这样

<if test="_parameter != null and _parameter != ''">
       
</if>

不要使用param1

2.dao层接口 只有一个参数 且绑定@Param时

getSectionListByTargetId(@Param("p") String target)

xml test要这样

<if test="p!= null and p != ''">
       
</if>

 3.dao层接口多个参数,且没有绑定@Param

getSectionListByTargetId(String target,String month)

 xml test要这样

 

<if test="param1 != null and param1 != ''">
       
</if>

不能直接使用 target或者month

4.dao成接口为对象时(UserInfo是对象)

getSectionListByTargetId(UserInfo user)

xml test(userId是对象的一个属性)

<if test="userId!= null and userId!= ''">
       
</if>

5.<collection>集合,多个参数

<collection property="teacherList" column="{marketUserId=market_user_id,sectionId=section_id}" javaType="ArrayList"
                        ofType="com.zhl.pojo.datamanage.reward.MarketTeacherMonthlyRewardEntity"
                        select="com.zhl.dao.reward.MarketRewardDao.getMarketTeacherMonthlyRewardList"/>
select * from zhl_market_teacher_monthly_reward where market_user_id = #{marketUserId} and section_id = #{sectionId};

注意:第一个sql  column处 marketUserId必须和第二个sql#{marketUserId}一致,第二个sql不能使用#{0} #{1}这样的占位符了

且 dao层

getMarketTeacherMonthlyRewardList(@Param("marketUserId") int marketUserId,@Param("sectionId")int sectionId);

也要使用@Param绑定参数

6.针对5,如果是一个参数

<collection property="teacherList" column="section_id" javaType="ArrayList"
                        ofType="com.zhl.pojo.datamanage.reward.MarketTeacherMonthlyRewardEntity"
                        select="com.zhl.dao.reward.MarketRewardDao.getMarketTeacherMonthlyRewardList"/>
select * from zhl_market_teacher_monthly_reward where market_user_id = #{0};

#{0}也行,如果还是写#{marketUserId},则需要绑定参数了;如果column只传了一个参数,实际多个,则多个参数都是用column传的这一个参数

 

结论,注意规范,保持参数一致

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值