SubjectMapper.xml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.yonge.cooleshow.biz.dal.dao.SubjectDao">
  8. <resultMap type="com.yonge.cooleshow.biz.dal.entity.Subject" id="Subject">
  9. <result column="id_" property="id"/>
  10. <result column="name_" property="name"/>
  11. <result column="code_" property="code"/>
  12. <result column="parent_subject_id_" property="parentSubjectId"/>
  13. <result column="img_" property="img"/>
  14. <result column="desc_" property="desc"/>
  15. <result column="create_time_" property="createTime"/>
  16. <result column="update_time_" property="updateTime"/>
  17. <result column="del_flag_" property="delFlag"/>
  18. </resultMap>
  19. <!-- 根据主键查询一条记录 -->
  20. <select id="get" resultMap="Subject">
  21. SELECT * FROM subject WHERE del_flag_ = 0 and id_ = #{id}
  22. </select>
  23. <!-- 全查询 -->
  24. <select id="findAll" resultMap="Subject">
  25. SELECT * FROM subject where del_flag_ = 0 ORDER BY id_
  26. </select>
  27. <!-- 向数据库增加一条记录 -->
  28. <insert id="insert" parameterType="com.yonge.cooleshow.biz.dal.entity.Subject" useGeneratedKeys="true"
  29. keyColumn="id"
  30. keyProperty="id">
  31. INSERT INTO subject (id_,name_,code_,parent_subject_id_,img_,create_time_,update_time_,desc_)
  32. VALUES(#{id},#{name},#{code},#{parentSubjectId},#{img},now(),now(),#{desc})
  33. </insert>
  34. <!-- 根据主键查询一条记录 -->
  35. <update id="update" parameterType="com.yonge.cooleshow.biz.dal.entity.Subject">
  36. UPDATE subject
  37. <set>
  38. <if test="delFlag != null">
  39. del_flag_ = #{delFlag},
  40. </if>
  41. <if test="parentSubjectId != null">
  42. parent_subject_id_ = #{parentSubjectId},
  43. </if>
  44. <if test="code != null">
  45. code_ = #{code},
  46. </if>
  47. <if test="img != null">
  48. img_ = #{img},
  49. </if>
  50. <if test="updateTime != null">
  51. update_time_ = NOW(),
  52. </if>
  53. <if test="name != null">
  54. name_ = #{name},
  55. </if>
  56. <if test="desc != null">
  57. desc_ = #{desc},
  58. </if>
  59. </set>
  60. WHERE id_ = #{id}
  61. </update>
  62. <!-- 根据主键删除一条记录 -->
  63. <update id="delete">
  64. UPDATE `subject` SET del_flag_ = 1 WHERE id_ = #{id} OR parent_subject_id_ = #{id}
  65. </update>
  66. <delete id="deleteById">
  67. update subject set del_flag_ = 1 where id_ = #{id} or parent_subject_id_ = #{id}
  68. </delete>
  69. <!-- 分页查询 -->
  70. <select id="queryPage" resultMap="Subject" parameterType="map">
  71. SELECT * FROM subject
  72. <include refid="querySubPageSql"/>
  73. ORDER BY id_
  74. <include refid="global.limit"/>
  75. </select>
  76. <!-- 查询当前表的总记录数 -->
  77. <select id="queryCount" resultType="int">
  78. SELECT COUNT(*) FROM subject
  79. <include refid="querySubPageSql"/>
  80. </select>
  81. <select id="findByParentId" resultMap="Subject">
  82. SELECT * FROM subject
  83. where del_flag_ = 0
  84. <if test="parentId != null">
  85. AND parent_subject_id_ = #{parentId}
  86. </if>
  87. </select>
  88. <sql id="querySubPageSql">
  89. where del_flag_ = 0
  90. <if test="parentId != null">
  91. AND parent_subject_id_ = #{parentId}
  92. </if>
  93. <if test="delFlag != null">
  94. AND del_flag_ = #{delFlag}
  95. </if>
  96. <if test="search != null and search != ''">
  97. AND (id_ like concat('%',#{search},'%') or name_ like concat('%',#{search},'%'))
  98. </if>
  99. <if test="queryType != null and queryType == 'category'">
  100. and (parent_subject_id_ = 0 or parent_subject_id_ is null)
  101. </if>
  102. <if test="queryType != null and queryType == 'list'">
  103. and parent_subject_id_ > 0
  104. </if>
  105. </sql>
  106. <select id="findBySubjectByIdList" resultMap="Subject">
  107. SELECT * FROM `subject` WHERE del_flag_ = 0 AND FIND_IN_SET(id_,#{subjectIdList})
  108. </select>
  109. <select id="findBySubjectIds" resultMap="Subject">
  110. SELECT * FROM subject WHERE del_flag_ = 0 and id_ IN
  111. <foreach collection="subjectIds" item="subjectId" separator="," open="(" close=")">
  112. #{subjectId}
  113. </foreach>
  114. </select>
  115. <select id="selectSubjectById" resultType="com.yonge.cooleshow.biz.dal.entity.Subject"
  116. parameterType="java.lang.String">
  117. SELECT * FROM subject WHERE del_flag_ = 0 and id_=#{lessonSubject}
  118. </select>
  119. </mapper>