StudentMapper.xml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.jeeplus.modules.test.manytomany.mapper.StudentMapper">
  4. <sql id="studentColumns">
  5. a.id AS "id",
  6. a.name AS "name",
  7. a.create_by AS "createBy.id",
  8. a.create_date AS "createDate",
  9. a.update_by AS "updateBy.id",
  10. a.update_date AS "updateDate",
  11. a.remarks AS "remarks",
  12. a.del_flag AS "delFlag"
  13. </sql>
  14. <sql id="studentJoins">
  15. </sql>
  16. <select id="get" resultType="Student" >
  17. SELECT
  18. <include refid="studentColumns"/>
  19. FROM test_student a
  20. <include refid="studentJoins"/>
  21. WHERE a.id = #{id}
  22. </select>
  23. <select id="findList" resultType="Student" >
  24. SELECT
  25. <include refid="studentColumns"/>
  26. FROM test_student a
  27. <include refid="studentJoins"/>
  28. <where>
  29. a.del_flag = #{DEL_FLAG_NORMAL}
  30. ${dataScope}
  31. <if test="name != null and name != ''">
  32. AND a.name = #{name}
  33. </if>
  34. </where>
  35. <choose>
  36. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  37. ORDER BY ${page.orderBy}
  38. </when>
  39. <otherwise>
  40. ORDER BY a.update_date DESC
  41. </otherwise>
  42. </choose>
  43. </select>
  44. <select id="findAllList" resultType="Student" >
  45. SELECT
  46. <include refid="studentColumns"/>
  47. FROM test_student a
  48. <include refid="studentJoins"/>
  49. <where>
  50. a.del_flag = #{DEL_FLAG_NORMAL}
  51. ${dataScope}
  52. </where>
  53. <choose>
  54. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  55. ORDER BY ${page.orderBy}
  56. </when>
  57. <otherwise>
  58. ORDER BY a.update_date DESC
  59. </otherwise>
  60. </choose>
  61. </select>
  62. <insert id="insert">
  63. INSERT INTO test_student(
  64. id,
  65. name,
  66. create_by,
  67. create_date,
  68. update_by,
  69. update_date,
  70. remarks,
  71. del_flag
  72. ) VALUES (
  73. #{id},
  74. #{name},
  75. #{createBy.id},
  76. #{createDate},
  77. #{updateBy.id},
  78. #{updateDate},
  79. #{remarks},
  80. #{delFlag}
  81. )
  82. </insert>
  83. <update id="update">
  84. UPDATE test_student SET
  85. name = #{name},
  86. update_by = #{updateBy.id},
  87. update_date = #{updateDate},
  88. remarks = #{remarks}
  89. WHERE id = #{id}
  90. </update>
  91. <!--物理删除-->
  92. <update id="delete">
  93. DELETE FROM test_student
  94. WHERE id = #{id}
  95. </update>
  96. <!--逻辑删除-->
  97. <update id="deleteByLogic">
  98. UPDATE test_student SET
  99. del_flag = #{DEL_FLAG_DELETE}
  100. WHERE id = #{id}
  101. </update>
  102. <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
  103. <select id="findUniqueByProperty" resultType="Student" statementType="STATEMENT">
  104. select * FROM test_student where ${propertyName} = '${value}'
  105. </select>
  106. </mapper>