<?xml version="1.0" encoding="UTF8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.q.dao.StudentMapper1"><!-- 插入数据--><insertid="insertData"parameterType="Student1">
insert into student
<trimprefix="("suffix=")"suffixOverrides=","><iftest="id !=null and id !=''">
id,
</if><iftest="name !=null and name !=''">
name,
</if><iftest="tid !=null and tid !=''">
tid,
</if><iftest="age !=null and age !=''">
age,
</if></trim><trimprefix="values ("suffix=")"suffixOverrides=","><iftest="id !=null and id !=''">
#{id},
</if><iftest="name !=null and name !=''">
#{name},
</if><iftest="tid !=null and tid !=''">
#{tid},
</if><iftest="age !=null and age !=''">
#{age},
</if></trim></insert><!-- 批量添加--><insertid="batchAdd"parameterType="Student1">
insert into student(
id, name, tid, age
)values
<foreachcollection="list"index="index"item="Student1"separator=",">
(#{Student1.id},#{Student1.name},#{Student1.tid},#{Student1.age})
</foreach></insert><!-- 更新数据--><updateid="updateInformation"parameterType="Student1">
update student
<set><iftest="name !=null and name !=''">
name =#{name},
</if><iftest="age !=null and age !=''">
age=#{age},
</if><iftest="tid !=null and tid !=''">
tid=#{tid},
</if></set>
where id=#{id};
</update><!-- 批量删除--><deleteid="batchDeletion"parameterType="list">
delete from student where id in
<foreachcollection="list"open="("close=")"separator=","item="id">
#{id}
</foreach></delete><selectid="getStudent"resultType="com.q.pojo.Student1">
select * from mybatis.student
<where><iftest="age != null">
age=#{age}
</if></where></select><selectid="getInformation"resultType="com.q.pojo.Student1"parameterType="Student1">
select *
from student
<where><bindname="name1"value="'%'+name+'%'"/><iftest="name !=null and name !=''">
and name like #{name1}
</if><iftest="age !=null and age !=''">
and age=#{age}
</if><iftest="id !=null and id !=''">
and id=#{id}
</if></where></select><!-- 批量查询--><selectid="bulkQuery"resultType="com.q.pojo.Student1"parameterType="list">
select *
from student where id in
<foreachcollection="list"open="("close=")"separator=","item="id"index="i">
#{id}
</foreach></select></mapper>
<?xml version="1.0" encoding="UTF8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!--绑定dao接口,会自动的找到sql语句--><mappernamespace="com.q.dao.BlogMapper"><insertid="addBook"parameterType="blog">
insert into mybatis.blog(id, title, author, create_time, views)
values (#{id}, #{title}, #{author}, #{create_time}, #{views});
</insert><!-- 这个方法是update--><updateid="upDateTest">
update mybatis.blog
<set><iftest="title !=null">
title =#{title},
</if></set>
where id =#{id}
</update><selectid="QueryBlog"parameterType="map"resultType="com.q.pojo.Blog">
select *
from mybatis.blog where 1=1
<iftest="title !=null">
and title=#{title}
</if><iftest="author !=null">
and author=#{author}
</if></select><!--sql片段,相当于封装--><sqlid="choose-when"><choose><whentest="title!=null">
title=#{title}
</when><whentest="author!=null">
and author=#{author}
</when><otherwise>
and views=#{views}
</otherwise></choose></sql><selectid="QueryBlogChoose"resultType="com.q.pojo.Blog"parameterType="map">
select * from mybatis.blog
<where><includerefid="choose-when"/></where></select><selectid="selectBlog"resultType="com.q.pojo.Blog"parameterType="map">
select *
from mybatis.blog
<where><foreachcollection="ids"item="id"open="and ("close=")"separator="or">
id =#{id}
</foreach></where></select><selectid="selectBlogByName"resultType="com.q.pojo.Blog"><bindname="blogName"value="'%'+title+'%'"/>
select * from mybatis.blog where title like #{blogName};
</select></mapper>