1. <?xml version="1.0" encoding="UTF-8" ?>
    2. <!--MyBatis的DTD约束-->
    3. <!DOCTYPE mapper
    4. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    5. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    6. <!--
    7. mapper:核心根标签
    8. namespace属性:名称空间
    9. -->
    10. <mapper namespace="com.itheima.mapper.StudentMapper">
    11. <sql id="select" >SELECT * FROM student</sql>
    12. <!--
    13. select:查询功能的标签
    14. id属性:唯一标识
    15. resultType属性:指定结果映射对象类型
    16. parameterType属性:指定参数映射对象类型
    17. -->
    18. <select id="selectAll" resultType="student">
    19. <include refid="select"/>
    20. </select>
    21. <select id="selectById" resultType="student" parameterType="int">
    22. <include refid="select"/> WHERE id = #{id}
    23. </select>
    24. <insert id="insert" parameterType="student">
    25. INSERT INTO student VALUES (#{id},#{name},#{age})
    26. </insert>
    27. <update id="update" parameterType="student">
    28. UPDATE student SET name = #{name},age = #{age} WHERE id = #{id}
    29. </update>
    30. <delete id="delete" parameterType="int">
    31. DELETE FROM student WHERE id = #{id}
    32. </delete>
    33. <select id="selectCondition" resultType="student" parameterType="student">
    34. <include refid="select"/>
    35. <where>
    36. <if test="id != null">
    37. id = #{id}
    38. </if>
    39. <if test="name != null">
    40. AND name = #{name}
    41. </if>
    42. <if test="age != null">
    43. AND age = #{age}
    44. </if>
    45. </where>
    46. </select>
    47. <select id="selectByIds" resultType="student" parameterType="list">
    48. <include refid="select"/>
    49. <where>
    50. <foreach collection="list" open="id IN (" close=")" item="id" separator=",">
    51. #{id}
    52. </foreach>
    53. </where>
    54. </select>
    55. </mapper>