<?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">
<mapper namespace="two">
<!--保存数据selectKey若启用则添加成功后id会自动返回-->
<insert id="save" parameterType="Student">
<!-- <selectKey resultType="int" keyProperty="id" order="AFTER">-->
<!-- SELECT LAST_INSERT_ID()-->
<!-- </selectKey>-->
insert into stu(
name,
age,
address
) values (
#{name},
#{age},
#{address}
)
</insert>
<!--保存数据selectKey若启用则添加成功后id会自动返回-->
<insert id="add" parameterType="Student">
<!-- <selectKey resultType="int" keyProperty="id" order="AFTER">-->
<!-- SELECT LAST_INSERT_ID()-->
<!-- </selectKey>-->
insert into stu(
name,
age,
address
) values (
#{name},
#{age},
#{address}
)
</insert>
<select id="queryMsg" resultType="Student">
select * from stu
</select>
<!--批量插入数据-->
<insert id="batchSave" parameterType="java.util.List">
insert into stu(
name,
age,
address
) values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.name},
#{item.age},
#{item.address}
)
</foreach>
</insert>
<!--更新数据-->
<update id="update" parameterType="Student">
update stu
<trim prefix="set" suffixOverrides=",">
<if test="name!=null">name = #{name},</if>
<if test="age!=null">age = #{age},</if>
<if test="address!=null">address = #{address},</if>
</trim>
where id = #{id}
</update>
<!--删除数据-->
<delete id="delete" parameterType="int">
delete from stu where id = #{id}
</delete>
<!--根据id返回一条记录-->
<select id="queryById" parameterType="int" resultType="Student">
select
id,
name,
age,
address
from stu
where id=#{id}
</select>
<!--分页记录-->
<select id="queryPage" resultType="Student">
select
id,
name,
age,
address
from stu
</select>
<!--查询结果装到listMap中返回-->
<select id="queryToListMap" resultType="map" parameterType="hashmap">
select
id,
name,
age,
address
from stu
</select>
</mapper>