<!-- <where> : 用来进行多条件处理--><selectid="getByCondition"parameterType="question"resultType="question">
select
<includerefid="allColumns"/>
from question
<where><iftest="title != null and title != ''">
and title like concat('%',#{title},'%')
</if><iftest="answer != null and answer != ''">
and answer like concat('%',#{answer},'%')
</if></where></select>
set
<!-- <set> : 有选择的更新,可以保证没有传值进来,不影响表中的数据 --><!-- 至少更新一个字段 --><updateid="modifyBySet"parameterType="question">
update question
<set><iftest="title != null and title != ''">
title = #{title},
</if><iftest="optionA != null and optionA != ''">
optionA = #{optionA},
</if><iftest="optionB != null and optionB != ''">
optionB = #{optionB},
</if><iftest="optionC != null and optionC != ''">
optionC = #{optionC},
</if><iftest="optionD != null and optionD != ''">
optionD = #{optionD},
</if><iftest="answer != null and answer != ''">
answer = #{answer},
</if></set>
where id = #{id}
</update>
foreach
<!-- <foreach> : 用来进行循环遍历的,可以批量处理,批量删除,批量增加,批量更新,查询也可以使用循环 --><!--查询操作--><selectid="getByIds"resultType="question">
select
<includerefid="allColumns"/>
from question
where id in
<!--
参数解析:
collection: 传入的数据类型,数组为'array',List集合为'list',Map集合为'map'
item: 遍历出来的临时变量或对象
separator: 多个变量或对象或语句之间的分隔符
open: 整个循环遍历前面的字符串
close: 整个循环遍历后面的字符串
--><foreachcollection="array"item="id"separator=","open="("close=")">
#{id}
</foreach></select>
<!--批量删除--><deleteid="removeByIds">
delete from question
where id in
<foreachcollection="array"open="("close=")"item="id"separator=",">
#{id}
</foreach></delete>
<selectid="findByBetweenId"parameterType="map"resultType="question">
select
<includerefid="allColumns"/>
from question
where id between #{begin} and #{end}
</select>
<!--Map<String, Object> map=mapper.getReturnMapOne(4);--><selectid="getReturnMapOne"resultType="map">
select title, answer
from question
where id = #{id}
</select>
<!--
表:
bookid int,
bookname varchar
实体类:
private Integer id;
private String name;
--><selectid="getAll"resultType="book">
select bookid id, bookname name
from book
</select>
使用ResultMap解决
<!--手工进行映射绑定,将列名于实体类中成员变量绑定--><mappernamespace="icu.sandink.mapper.IBookMapper"><!--手工映射绑定--><resultMapid="bookmap"type="book"><!--主键绑定--><idproperty="id"column="booked"/><!--非主键绑定--><resultproperty="name"column="bookname"/></resultMap><selectid="getAll"resultMap="bookmap">
select bookid, bookname
from book
</select></mapper>