请教一下mybatis 的传入参数如何既有对象又有单个参数?

mybatis 的传入参数如何既有对象又有单个参数


冉冉说
浏览 2065回答 3
3回答

catspeake

使用@Param注解1List<Person>&nbsp;query(@Param("query")&nbsp;PersonQuery&nbsp;query,&nbsp;@Param("offset")&nbsp;int&nbsp;offset,&nbsp;@Param("rows")&nbsp;int&nbsp;rows);mapper中sql使用#{参数名}获取参数。#{query.a}是取PersonQuery对象里的a字段的值12345<select&nbsp;id="query"&nbsp;resultMap="result">&nbsp;&nbsp;&nbsp;&nbsp;SELECT&nbsp;*&nbsp;FROM&nbsp;XXX&nbsp;&nbsp;&nbsp;&nbsp;WHERE&nbsp;A=#{query.a}&nbsp;AND&nbsp;B=#{query.b}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LIMIT&nbsp;#{offset},#{rows}</select>

撒科打诨

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>
打开App,查看更多内容
随时随地看视频慕课网APP