3 回答
TA贡献1111条经验 获得超0个赞
使用@Param注解
1 | List<Person> query( @Param ( "query" ) PersonQuery query, @Param ( "offset" ) int offset, @Param ( "rows" ) int rows); |
mapper中sql使用#{参数名}获取参数。#{query.a}是取PersonQuery对象里的a字段的值
12345 | < select id = "query" resultMap = "result" > SELECT * FROM XXX WHERE A=#{query.a} AND B=#{query.b} LIMIT #{offset},#{rows} </ select > |
TA贡献1934条经验 获得超2个赞
mybatis支持foreach语句,
语法大致如下:
<update id="batchUpdate">
update tblsupertitleresult
<trim prefix="set" suffixOverrides=",">
<trim prefix="checkState =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.checkState!=null">
when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.checkState}
</if>
</foreach>
</trim>
<trim prefix=" correctDate =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.correctDate!=null">
when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.correctDate}
</if>
</foreach>
</trim>
<trim prefix="result =case" suffix="end," >
<foreach collection="list"item="i" index="index">
<if test="i.result!=null">
when (userHhCode=#{i.userHhCode} and titleId=#{i.titleId}) then #{i.result}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or"item="i" index="index" >
(userHhCode =#{i.userHhCode} andtitleId=#{i.titleId})
</foreach>
</update>
添加回答
举报