<?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="com.zelin.mapper.StudentMapper"><!--1-查询所有学生--><selectid="findAll"resultType="student">
select st.*,cname from student st,classes c where c.cid = st.cid
</select><!--2-自动插入学生--><insertid="insert"parameterType="student"useGeneratedKeys="true"keyProperty="sid">
insert into student values (null,#{sname},#{sex},#{age},#{addr},#{cid})
</insert><!--3-查询指定Id的学生--><selectid="findById"resultType="student">
select st.*,cname from student st,classes c where c.cid = st.cid and sid=#{value}
</select><!--4-修改学生--><updateid="update"parameterType="student">
update student set sname=#{sname},sex=#{sex},age=#{age},addr=#{addr},cid=#{cid} where sid=#{sid}
</update><!--5-根据Id删除指定的学生--><deleteid="deleteById"parameterType="int">
delete from student where sid=#{value}
</delete><!--6-条件查询(方式一:使用#方式进行条件查询)--><selectid="findByStu"parameterType="student"resultType="student">
select st.*,cname from student st,classes c where c.cid = st.cid and sname like #{sname} and addr like #{addr}
</select><!--7-条件查询(方式二:使用$方式进行条件查询)--><selectid="findByStu2"parameterType="student"resultType="student">
select st.*,cname from student st,classes c where c.cid = st.cid and sname like "%${sname}%" and addr like "%${addr}%"
</select><!--8.动态SQL查询:关键字查询学生--><selectid="searchByWords"resultType="student"parameterType="student">
select st.*,cname from student st,classes c
<where>
st.cid = c.cid
<iftest="sname !=null and sname!=''">
and sname like '%${sname}%'
</if><iftest="addr !=null and addr!=''">
and addr like '%${addr}%'
</if></where></select><!--9-分页查询:查询所有的学生总数--><selectid="findByCount"resultType="long">
select count(*) from student st,classes c where st.cid = c.cid
</select><!--10-分页查询:查询指定页 指定每页大小下的学生集合-->
<select id ="findByPage" parameterType="pageVo" resultType="student">
select st.*,cname from student st,classes c where c.cid=st.cid limit #{page},#{pageSize}
</select></mapper>
1.1.1.2 ClassesMapper.xml
<?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="com.zelin.mapper.ClassesMapper"><!--1-查询所有班级--><selectid="findAll"resultType="classes">
select * from classes
</select></mapper>