mybatis基本查询映射文件

时间:2020-08-09 11:37:04 类型:JAVA
字号:    

mybatis基本查询映射文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?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.yt.dao.StudentDao">
     <!--根据uid查询一个用户信息 -->
    <select id="selectStudentById" parameterType="Integer" resultType="com.yt.pojo.Student">
        select * from student where id = #{id}
    </select>
    <!-- 添加一个学生,为 zhuangzi.polo.Users 的属性值 -->
    <insert id="addStudent" parameterType="student">
    insert into student (names,email,sex,blood,hobby,time,pic) values(#{names},#{email},#{sex},#{blood},#{hobby},#{time},#{pic})
    </insert>
    <!-- 修改一个学生,#{names}为 zhuangzi.polo.Users 的属性值 -->
    <update id="editStudent" parameterType="student">
    update  student set  names = #{names},
                         email = #{email},
                         sex   = #{sex},
                         blood = #{blood},
                         hobby = #{hobby},
                         pic   = #{pic}
                         where id = #{id}
    </update>
    <!-- 查询学生信息 -->
    <select id="selectStudent" resultType="student" parameterType="student">
        <if test="names != null and names != '' ">
               <bind name="param_names" value="'%' + names + '%'" />
        </if>
        select * from student
        <where>
            <if test="names != null and names != '' ">
                and names like #{param_names}
            </if>
            <if test="sex != null and sex != '' ">
                and sex=#{sex}
            </if >
        </where>
    </select>
    <!-- 删除一个学生 -->
    <delete id="deleteStudent" parameterType="Integer">
        delete from student where id = #{id}
    </delete>
    <!-- 删除多个学生方法1 -->
    <delete id="deleteStudents" parameterType="String">
        delete from student where id in (${ids})
    </delete>
    <!-- 删除多个学生方法2 -->
    <delete id="delsStudents" parameterType="Integer">
        delete from student where id in
         <foreach item="id" index="index" collection="array"
    open="(" separator="," close=")">
              ${id}
          </foreach>
    </delete>
</mapper>


<