<insertid="inserUser"parameterType="User"statementType="PREPARED"keyProperty="id"useGeneratedKeys="true">
insert into User (userName,password) values (#{userName},#{password})
</insert>
packagecheng.book.map;importorg.apache.ibatis.annotations.Delete;publicinterfaceInterfaceUser{@Delete("delete from User where id=#{id}")publicvoiddeleteUser(Integerid);}
<resultMaptype="User"id="U"><idproperty="id"column="id"/><resultproperty="userName"column="userName"/><resultproperty="password"column="password"/></resultMap><selectid="selectUsers"resultMap="U">
select id,userName,password from User
</select>
<resultMaptype="Author"id="AuthorMap"><idproperty="id"column="author.id"/><resultproperty="realName"column="realName"/><resultproperty="IDCard"column="IDCard"/><!-- 联合查询 --><associationproperty="user"column="userID"javaType="User"><idproperty="id"column="user.id"/><resultproperty="userName"column="userName"/><resultproperty="password"column="password"/></association></resultMap><selectid="selectAuthorJoin"resultMap="AuthorMap">
select * from author inner join user on user.id=author.userID
</select>
<!-- 构造函数 --><resultMaptype="Author"id="AuthorMapByCon"><idproperty="id"column="author.id"/><resultproperty="realName"column="realName"/><resultproperty="IDCard"column="IDCard"/><associationproperty="user"column="userID"javaType="User"><constructor><argcolumn="userName"javaType="String"/><argcolumn="password"javaType="String"/></constructor></association></resultMap><selectid="selectAuthorJoin2"resultMap="AuthorMapByCon">
select * from author inner join user on user.id=author.userID
</select>
<resultMaptype="User"id="visitMap"><idproperty="id"column="id"/><resultproperty="userName"column="userName"/><collectionproperty="visitList"javaType="ArrayList"column="visitID"ofType="cheng.book.pojo.Visit"><resultproperty="visitID"column="visitID"/><resultproperty="visitIP"column="visitIP"/><resultproperty="visitDate"column="visitDate"/></collection></resultMap><selectid="selectVisit"resultMap="visitMap">
select * from User inner join visit on user.id=visit.userID
</select>
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="/"><selectid="selectReaderMoney"resultType="Readers"parameterType="Readers">
select * from reader
where 1=1
<iftest="money!=null">
and money>#{money}
</if></select></mapper>
<selectid="selectUserChoose"resultType="User"parameterType="User">
select * from User where 1=1
<choose><whentest="userName!=null">
and userName like #{userName}
</when><whentest="id!=0">
and id=#{id}
</when><otherwise>
and password is not null
</otherwise></choose></select>
<selectid="selectUserWhere"resultType="User"parameterType="User">
select * from User
<where><iftest="userName!=null">
and userName like #{userName}
</if><iftest="id!=null">
and id=#{id}
</if></where></select>
<updateid="updateUserSet"parameterType="User">
update User
<set><iftest="userName!=null">userName=#{userName},</if><iftest="password!=null">password=#{password},</if></set></update>
<selectid="selectUserForeach"resultType="User"parameterType="User">
select * from User
<where>
id in
<foreachcollection="list"item="item"index="index"open="("separator=","close=")">
#{item}
</foreach></where></select>
<insertid="insertUserForeach">
insert into User (userName,password) values
<foreachitem="item"index="key"collection="list"open=""separator=","close="">
(#{item.userName},#{item.password})
</foreach></insert>