<?xml version="1.1" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-////DTD Mapper 3.0//EN"
"/dtd/">
<!--namespace: 代表xml的名称,类似java包名-->
<mapper namespace="">
<!--
select: 代表进行查询操作。
id: 之前的方法名称,具有唯一性。
resultType: 返回值类型。
如果返回的是对象,直接书写对象类型的的完整名。
如果是集合,书写的是集合的泛型
parameterType: 参数类型,可以省略。
-->
<select resultType="product" >
select * from product
</select>
<select resultType="product" >
select * from product where id=2
</select>
<select resultType="product" >
select * from product where id=#{param1} and name=#{param2}
</select>
<select resultType="product" >
select * from product where id=${param1} and name=#{param2}
</select>
<select resultType="product" >
select * from product where name like concat ('%','芒果','%')
</select>
<sql >
id,name,address,categoryId
</sql>
<select resultMap="myresultMap1">
select <include ref/>from product where name like concat ('%','芒果','%')
</select>
<resultMap type="">
</resultMap>
<select resultMap="myresultMap1">
select id,name,address,categoryId from product
<where>
<if test="id!=null">
and id=#{id}
</if>
<if test="ids!=null">
and id in
<foreach collection="ids" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="categoryId != null">
and categoryId= #{categoryId}
</if>
<if test="categoryIds != null">
and categoryId in
<foreach collection="categoryIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="name != null">
and name like concat('%',#{name},'%')
</if>
</where>
</select>
<insert >
insert into product (name,address) values (#{name},#{address})
<selectKey resultType="integer" keyColumn="newId" keyProperty="product" order="AFTER">
select last_insert_id() as newId
</selectKey>
</insert>
<update >
insert into product (name,address) values (#{name},#{address})
</update>
<delete >
delete from product where id=#{param1}
</delete>
</mapper>