if和where:xxx.yy表示从vo中读取属性值
<where>可以自动取出第一个and
<where>
<iftest="xxx!=null">
<iftest="xxx.yy!=null and xxx.yy!=''">
and····
</if>
<iftest="xxx.zz!=null and xxx.zz!=''">
and name=${xxx.zz}
</if>
</if>
</where>
建议对单表的东西进行单独抽取sql
<sqlid="">
列名
</sql>
引用:如果不在同一个文件就是namespace+id
<includerefid="">
</include>
foreach的使用
collection:集合的属性
open:开始循坏拼接的串
close:结束循坏拼接的串
item:每次循环所取到的对象
separator:循环中间拼接的串
and (id=16,id=22,id=15)
<foreachcollection="ids"open="and ("close=")"item="id"seporator=",">
#{id}
</foreach>
resultMap一对一Orders类中加入一个User类属性
<resultMapid="aaaaaaaaaaaa"type="orders">
<idcolumn=""property="">
<resultcolumn=""property="">
····
association:用户对关联的单条记录映射
property:要将关联信息映射到orders的哪个属性中
javaType:关联信息映射到orders的属性的类型,是user的类型
<association property="属性名" javaType="属性类型名">
<id column="" property=""/>
user表的唯一标识
<result column="" property=""/>
</association
></resultMap>
resultMap一对多orders类中加入属性List<OrderDetail> orderDetails
可以用extend继承只写没有的,也可以不继承就需要全部写ofType:集合中pojo的类型
<resultMapid=""type=""extend="aaaaaaaaaaaa">
<collectionproperty="属性名"ofType="集合中pojo类型">
<idcolumn=""property=""/>
<resultcolumn=""property="">
</collection></resultMap>
resultMap一对多复杂的查询:
user类中加入List<Order> orderlist(list)
Order中有List<OrderDetail> orderDetails(list)
OrderDetail中有item属性(pojo)
class user{ int id; ···· List<Order> orderlist}
class Order{ ···· List<OrderDetail> orderDetails;}
class OrderDetail{ ···· private Item item;}
resultMap:实现延迟加载用这个,为了方便
<resultMapid=""type="user">
<idcolumn=""property="">
<resultcolumn=""property="">
····
<!--List<Order> orderlist(list)-->
<collectionproperty="orderlist"javaType="">
<idcolumn=""property="">
<resultcolumn=""property="">
`````
<collectionproperty="orderDetails"ofType="">
<idcolumn=""property="">
<resultcolumn=""property="">
`````
<assoctionproperty="item"javaType="">
<idcolumn=""property="">
<resultcolumn=""property="">
`````
</assoction>
</collection>
</collection>
</resultMap>
延迟加载的配置:在sqlMapConfig中配置
<settings>
<settingname="lazyLoadingEnabled"value="true"/>打开延迟加载总开关(默认为false)
<settingname="aggressiveLazyLoading"value="false">要设为false才是按需加载(可实现延迟加载)(默认为true) 缺一不可
</settings>
区别:resultMap和resultType有简单的现成的用resultType方便获取关联信息用resultMap