1
0

GoodsAttributeDao.xml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.kmall.admin.dao.GoodsAttributeDao">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.admin.entity.GoodsAttributeEntity" id="goodsAttributeMap">
  6. <result property="id" column="id"/>
  7. <result property="goodsId" column="goods_id"/>
  8. <result property="merchSn" column="merch_sn"/>
  9. <result property="attributeId" column="attribute_id"/>
  10. <result property="value" column="value"/>
  11. </resultMap>
  12. <select id="queryObject" resultType="com.kmall.admin.entity.GoodsAttributeEntity">
  13. select
  14. id,
  15. goods_id,
  16. merch_sn,
  17. attribute_id,
  18. value
  19. from mall_goods_attribute
  20. where id = #{id}
  21. </select>
  22. <select id="queryList" resultType="com.kmall.admin.entity.GoodsAttributeEntity">
  23. select
  24. mall_goods_attribute.id,
  25. mall_goods_attribute.goods_id,
  26. mall_goods_attribute.merch_sn,
  27. mall_goods_attribute.attribute_id,
  28. mall_goods_attribute.value,
  29. mall_goods.name goods_name,
  30. mall_attribute.name attribute_name
  31. from mall_goods_attribute
  32. LEFT JOIN mall_goods ON mall_goods.id = mall_goods_attribute.goods_id
  33. LEFT JOIN mall_attribute ON mall_attribute.id = mall_goods_attribute.attribute_id
  34. WHERE 1=1
  35. <if test="goodsId != null and goodsId != ''">
  36. AND mall_goods_attribute.goods_id = #{goodsId}
  37. </if>
  38. <if test="attributeId != null and attributeId != ''">
  39. AND mall_goods_attribute.attribute_id = #{attributeId}
  40. </if>
  41. <choose>
  42. <when test="sidx != null and sidx.trim() != ''">
  43. order by ${sidx} ${order}
  44. </when>
  45. <otherwise>
  46. order by id desc
  47. </otherwise>
  48. </choose>
  49. <if test="offset != null and limit != null">
  50. limit #{offset}, #{limit}
  51. </if>
  52. </select>
  53. <select id="queryTotal" resultType="int">
  54. select count(*) from mall_goods_attribute
  55. WHERE 1=1
  56. <if test="goodsId != null and goodsId != ''">
  57. AND goods_id = #{goodsId}
  58. </if>
  59. <if test="attributeId != null and attributeId != ''">
  60. AND attribute_id = #{attributeId}
  61. </if>
  62. </select>
  63. <insert id="save" parameterType="com.kmall.admin.entity.GoodsAttributeEntity" useGeneratedKeys="true" keyProperty="id">
  64. insert into mall_goods_attribute(
  65. `goods_id`,
  66. `merch_sn`,
  67. `attribute_id`,
  68. `value`)
  69. values(
  70. #{goodsId},
  71. #{merchSn},
  72. #{attributeId},
  73. #{value})
  74. </insert>
  75. <update id="update" parameterType="com.kmall.admin.entity.GoodsAttributeEntity">
  76. update mall_goods_attribute
  77. <set>
  78. <if test="goodsId != null">`goods_id` = #{goodsId},</if>
  79. <if test="merchSn != null">`merch_sn` = #{merchSn},</if>
  80. <if test="attributeId != null">`attribute_id` = #{attributeId},</if>
  81. <if test="value != null">`value` = #{value}</if>
  82. </set>
  83. where id = #{id}
  84. </update>
  85. <update id="updateByGoodsIdAttributeId" parameterType="com.kmall.admin.entity.GoodsAttributeEntity">
  86. update mall_goods_attribute
  87. <set>
  88. <if test="value != null">`value` = #{value}</if>
  89. </set>
  90. where goods_id = #{goodsId} AND attribute_id = #{attributeId}
  91. </update>
  92. <delete id="delete">
  93. delete from mall_goods_attribute where id = #{value}
  94. </delete>
  95. <delete id="deleteByGoodsId">
  96. delete from mall_goods_attribute where goods_id = #{goodsId}
  97. </delete>
  98. <delete id="deleteBatch">
  99. delete from mall_goods_attribute where id in
  100. <foreach item="id" collection="array" open="(" separator="," close=")">
  101. #{id}
  102. </foreach>
  103. </delete>
  104. </mapper>