1
0

CartDao.xml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.CartDao">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.admin.entity.CartEntity" id="cartMap">
  6. <result property="id" column="id"/>
  7. <result property="userName" column="user_name"/>
  8. <result property="userId" column="user_id"/>
  9. <result property="sessionId" column="session_id"/>
  10. <result property="goodsId" column="goods_id"/>
  11. <result property="goodsSn" column="goods_sn"/>
  12. <result property="productId" column="product_id"/>
  13. <result property="goodsName" column="goods_name"/>
  14. <result property="marketPrice" column="market_price"/>
  15. <result property="retailPrice" column="retail_price"/>
  16. <result property="number" column="number"/>
  17. <result property="goodsSpecificationNameValue" column="goods_specification_name_value"/>
  18. <result property="goodsSpecificationIds" column="goods_specification_ids"/>
  19. <result property="checked" column="checked"/>
  20. <result property="listPicUrl" column="list_pic_url"/>
  21. </resultMap>
  22. <select id="queryObject" resultType="com.kmall.admin.entity.CartEntity">
  23. select * from mall_cart where id = #{value}
  24. </select>
  25. <select id="queryList" resultMap="cartMap">
  26. select a.* ,b.nickname as user_name
  27. from mall_cart a
  28. left join mall_user b on a.user_id = b.id
  29. where 1=1
  30. <if test="userId != null">
  31. AND a.user_id = #{userId}
  32. </if>
  33. <choose>
  34. <when test="sidx != null and sidx.trim() != ''">
  35. order by ${sidx} ${order}
  36. </when>
  37. <otherwise>
  38. order by id desc
  39. </otherwise>
  40. </choose>
  41. <if test="offset != null and limit != null">
  42. limit #{offset}, #{limit}
  43. </if>
  44. </select>
  45. <select id="queryTotal" resultType="int">
  46. select count(*) from mall_cart where 1=1
  47. <if test="userId != null">
  48. AND mall_cart.user_id = #{userId}
  49. </if>
  50. </select>
  51. <insert id="save" parameterType="com.kmall.admin.entity.CartEntity" useGeneratedKeys="true" keyProperty="id">
  52. insert into mall_cart
  53. (
  54. `user_id`,
  55. `session_id`,
  56. `goods_id`,
  57. `goods_sn`,
  58. `product_id`,
  59. `goods_name`,
  60. `market_price`,
  61. `retail_price`,
  62. `number`,
  63. `goods_specification_name_value`,
  64. `goods_specification_ids`,
  65. `checked`,
  66. `list_pic_url`
  67. )
  68. values
  69. (
  70. #{userId},
  71. #{sessionId},
  72. #{goodsId},
  73. #{goodsSn},
  74. #{productId},
  75. #{goodsName},
  76. #{marketPrice},
  77. #{retailPrice},
  78. #{number},
  79. #{goodsSpecificationNameValue},
  80. #{goodsSpecificationIds},
  81. #{checked},
  82. #{listPicUrl}
  83. )
  84. </insert>
  85. <update id="update" parameterType="com.kmall.admin.entity.CartEntity">
  86. update mall_cart
  87. <set>
  88. <if test="userId != null">`user_id` = #{userId},</if>
  89. <if test="sessionId != null">`session_id` = #{sessionId},</if>
  90. <if test="goodsId != null">`goods_id` = #{goodsId},</if>
  91. <if test="goodsSn != null">`goods_sn` = #{goodsSn},</if>
  92. <if test="productId != null">`product_id` = #{productId},</if>
  93. <if test="goodsName != null">`goods_name` = #{goodsName},</if>
  94. <if test="marketPrice != null">`market_price` = #{marketPrice},</if>
  95. <if test="retailPrice != null">`retail_price` = #{retailPrice},</if>
  96. <if test="number != null">`number` = #{number},</if>
  97. <if test="goodsSpecificationNameValue != null">`goods_specification_name_value` =
  98. #{goodsSpecificationNameValue},
  99. </if>
  100. <if test="goodsSpecificationIds != null">`goods_specification_ids` = #{goodsSpecificationIds},</if>
  101. <if test="checked != null">`checked` = #{checked},</if>
  102. <if test="listPicUrl != null">`list_pic_url` = #{listPicUrl}</if>
  103. </set>
  104. where id = #{id}
  105. </update>
  106. <delete id="delete">
  107. delete from mall_cart where id = #{value}
  108. </delete>
  109. <delete id="deleteBatch">
  110. delete from mall_cart where id in
  111. <foreach item="id" collection="array" open="(" separator="," close=")">
  112. #{id}
  113. </foreach>
  114. </delete>
  115. </mapper>