GoodsAttributeDao.xml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. <choose>
  36. <when test="sidx != null and sidx.trim() != ''">
  37. order by ${sidx} ${order}
  38. </when>
  39. <otherwise>
  40. order by id desc
  41. </otherwise>
  42. </choose>
  43. <if test="offset != null and limit != null">
  44. limit #{offset}, #{limit}
  45. </if>
  46. </select>
  47. <select id="queryTotal" resultType="int">
  48. select count(*) from mall_goods_attribute
  49. WHERE 1=1
  50. <if test="goodsId != null and goodsId != ''">
  51. AND mall_goods_attribute.goods_id = #{goodsId}
  52. </if>
  53. </select>
  54. <insert id="save" parameterType="com.kmall.admin.entity.GoodsAttributeEntity" useGeneratedKeys="true" keyProperty="id">
  55. insert into mall_goods_attribute(
  56. `goods_id`,
  57. `attribute_id`,
  58. `value`)
  59. values(
  60. #{goodsId},
  61. #{attributeId},
  62. #{value})
  63. </insert>
  64. <update id="update" parameterType="com.kmall.admin.entity.GoodsAttributeEntity">
  65. update mall_goods_attribute
  66. <set>
  67. <if test="goodsId != null">`goods_id` = #{goodsId},</if>
  68. <if test="attributeId != null">`attribute_id` = #{attributeId},</if>
  69. <if test="value != null">`value` = #{value}</if>
  70. </set>
  71. where id = #{id}
  72. </update>
  73. <update id="updateByGoodsIdAttributeId" parameterType="com.kmall.admin.entity.GoodsAttributeEntity">
  74. update mall_goods_attribute
  75. <set>
  76. <if test="value != null">`value` = #{value}</if>
  77. </set>
  78. where goods_id = #{goodsId} AND attribute_id = #{attributeId}
  79. </update>
  80. <delete id="delete">
  81. delete from mall_goods_attribute where id = #{value}
  82. </delete>
  83. <delete id="deleteByGoodsId">
  84. delete from mall_goods_attribute where goods_id = #{goodsId}
  85. </delete>
  86. <delete id="deleteBatch">
  87. delete from mall_goods_attribute where id in
  88. <foreach item="id" collection="array" open="(" separator="," close=")">
  89. #{id}
  90. </foreach>
  91. </delete>
  92. </mapper>