GoodsCategoryMapper.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.ym.mec.biz.dal.dao.GoodsCategoryDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.GoodsCategory" id="GoodsCategory">
  9. <result column="id_" property="id"/>
  10. <result column="name_" property="name"/>
  11. <result column="img_" property="img"/>
  12. <result column="parent_id_" property="parentId"/>
  13. <result column="order_no_" property="orderNo"/>
  14. <result column="del_flag_" property="delFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  15. <result column="desc_" property="desc"/>
  16. <result column="update_time_" property="updateTime"/>
  17. <result column="create_time_" property="createTime"/>
  18. <collection property="subjects" ofType="com.ym.mec.biz.dal.entity.Subject">
  19. <result property="id" column="subject_id_"/>
  20. <result property="name" column="subject_name_"/>
  21. </collection>
  22. </resultMap>
  23. <!-- 根据主键查询一条记录 -->
  24. <select id="get" resultMap="GoodsCategory">
  25. SELECT * FROM goods_category WHERE id_ = #{id}
  26. </select>
  27. <!-- 全查询 -->
  28. <select id="findAll" resultMap="GoodsCategory">
  29. SELECT * FROM goods_category ORDER BY id_
  30. </select>
  31. <!-- 向数据库增加一条记录 -->
  32. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.GoodsCategory" useGeneratedKeys="true" keyColumn="id"
  33. keyProperty="id">
  34. INSERT INTO goods_category (id_,name_,img_,parent_id_,order_no_,desc_,update_time_,create_time_)
  35. VALUES(#{id},#{name},#{img},#{parentId},#{orderNo},#{desc},now(),now())
  36. </insert>
  37. <!-- 根据主键查询一条记录 -->
  38. <update id="update" parameterType="com.ym.mec.biz.dal.entity.GoodsCategory">
  39. UPDATE goods_category
  40. <set>
  41. <if test="parentId != null">
  42. parent_id_ = #{parentId},
  43. </if>
  44. <if test="delFlag != null">
  45. del_flag_ = #{delFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  46. </if>
  47. <if test="orderNo != null">
  48. order_no_ = #{orderNo},
  49. </if>
  50. <if test="updateTime != null">
  51. update_time_ = NOW(),
  52. </if>
  53. <if test="img != null">
  54. img_ = #{img},
  55. </if>
  56. <if test="desc != null">
  57. desc_ = #{desc},
  58. </if>
  59. <if test="name != null">
  60. name_ = #{name},
  61. </if>
  62. </set>
  63. WHERE id_ = #{id}
  64. </update>
  65. <!-- 根据主键删除一条记录 -->
  66. <delete id="delete">
  67. UPDATE goods_category SET del_flag_ = 1 WHERE id_ = #{id}
  68. </delete>
  69. <!-- 分页查询 -->
  70. <select id="queryPage" resultMap="GoodsCategory" parameterType="map">
  71. SELECT gc.*,s.id_ subject_id_,s.name_ subject_name_
  72. FROM (
  73. SELECT * FROM goods_category
  74. <include refid="queryPageSql"/>
  75. <include refid="global.limit"/>
  76. ) gc
  77. LEFT JOIN subject_goods_mapper sgm ON sgm.goods_category_id_ = gc.id_
  78. LEFT JOIN `subject` s ON s.id_ = sgm.subject_id_
  79. </select>
  80. <sql id="queryPageSql">
  81. <where>
  82. <if test="parentId != null">
  83. parent_id_ = #{parentId}
  84. </if>
  85. <if test="delFlag != null">
  86. AND del_flag_ = #{delFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  87. </if>
  88. </where>
  89. </sql>
  90. <!-- 查询当前表的总记录数 -->
  91. <select id="queryCount" resultType="int">
  92. SELECT COUNT(id_) FROM goods_category
  93. <include refid="queryPageSql"/>
  94. </select>
  95. <select id="findByParentId" resultMap="GoodsCategory">
  96. SELECT * FROM goods_category WHERE parent_id_ = #{parentId} AND del_flag_ = #{delFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  97. </select>
  98. </mapper>