学生类的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">
<mapper namespace="com.keke.dao.StudentInfoDao">
<resultMap id="BaseResultMap" type="StudentInfo">
<id column="sid" property="sid" />
<result column="sname" property="sname" />
<result column="sage" property="sage" />
<result column="sphoneno" property="sphoneno" />
<result column="ssex" property="ssex" />
<result column="cid" property="cid" />
<result column="cname" property="cname"></result>
</resultMap>
<!--1、查询所有学生数据,主外键关联查询-->
<select id="findAll" parameterType="StudentInfo" resultMap="BaseResultMap">
select s.*,c.cname from studentinfo s,classinfo c where s.cid=c.cid
</select>
<!-- 2、根据学生某个条件查询相关数据-->
<select id="findName" resultMap="BaseResultMap" parameterType="string">
select * from studentinfo where sname=#{sname}
</select>
<!--3、查询某个学生信息-->
<select id="findById" resultMap="BaseResultMap" parameterType="integer">
select * from studentinfo where sid=#{sid}
</select>
<!--4根据学生姓名模糊查询-->
<select id="findLikeName" parameterType="string" resultMap="BaseResultMap">
select * from studentinfo where sname like "%"#{sname}"%"
</select>
<select id="findLikeName1" parameterType="StudentInfo" resultMap="BaseResultMap">
<bind name="sname" value="'%'+sname+'%'"></bind>
select * from studentinfo where sname like ${sname}
</select>
<!--5、根据学生年龄和姓名查询学生信息-->
<select id="findByageAndname" resultMap="BaseResultMap" parameterType="map">
<![CDATA[
select * from studentinfo where sname like "%"#{sname}"%" and sage>#{sage}
]]>
</select>
<!--6、查询学生信息,参数是map-->
<!--7、删除某个学生信息-->
<select id="deleteStudentInfoById" parameterType="int" resultMap="BaseResultMap">
delete from studentinfo where sid=#{sid}
</select>
<!--8、修改某个学生信息-->
<select id="udateStudentInfo" resultMap="BaseResultMap" parameterType="StudentInfo">
update studentinfo set sname=#{sname},sage=#{sage},sphoneno=#{sphoneno},ssex=#{ssex} where sid=#{sid}
</select>
<!--9、添加某个学生信息-->
<select id="insterStudentInfo" parameterType="StudentInfo" resultMap="BaseResultMap">
insert into studentinfo (sid,sname,sage,sphoneno,ssex)
values (null,#{sname},#{sage},#{sphoneno},#{ssex})
</select>
<!--10.动态修改-->
<select id="updateStudentInfoByDsq" resultMap="BaseResultMap" parameterType="StudentInfo">
update studentinfo
<set>
<if test="sname !=null and sname !=''" >
sname=#{sname}
</if>
<if test="sage !=null and sage !=''" >
sage=#{sage}
</if>
<if test="sphoneno !=null and sphoneno !=''" >
sphoneno=#{sphoneno}
</if>
<if test="ssex !=null and ssex !=''" >
ssex=#{ssex}
</if>
<if test="cid !=null and cid !=''" >
cid=#{cid}
</if>
where sid=#{sid}
</set>
</select>
<!--//11.动态查询