1
0

GoodsAttributeDao.xml 3.8 KB

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