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传的这一个参数
结论,注意规范,保持参数一致