ProductMapper.xml 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.example.mapper.ProductMapper">
  6. <sql id="Base_Column_List">
  7. id,product_state,product_name,product_icons,product_ids,product_bid_price,product_sell_price
  8. </sql>
  9. <select id="selectAll" resultType="com.example.entity.Product">
  10. select
  11. <include refid="Base_Column_List" />
  12. from product
  13. <where>
  14. <if test="id != null"> and id = #{id}</if>
  15. <if test="productState != null"> and product_state like concat('%', #{productState}, '%')</if>
  16. <if test="productName != null"> and product_name like concat('%', #{productName}, '%')</if>
  17. <if test="productIcons != null"> and product_icons like concat('%', #{productIcons}, '%')</if>
  18. <if test="productTypeIds != null"> and product_type_ids like concat('%', #{productIds}, '%')</if>
  19. <if test="productBidPrice != null"> and product_bid_price = #{productBidPrice}</if>
  20. <if test="productSellPrice != null"> and product_sell_price = #{productSellPrice}</if>
  21. </where>
  22. order by id desc
  23. </select>
  24. <select id="selectById" resultType="com.example.entity.Product">
  25. select
  26. <include refid="Base_Column_List" />
  27. from product
  28. where id = #{id}
  29. </select>
  30. <delete id="deleteById">
  31. delete from product
  32. where id = #{id}
  33. </delete>
  34. <insert id="insert" parameterType="com.example.entity.Product" useGeneratedKeys="true">
  35. insert into product
  36. <trim prefix="(" suffix=")" suffixOverrides=",">
  37. <if test="id != null">id,</if>
  38. <if test="productState != null">product_state,</if>
  39. <if test="productName != null">product_name,</if>
  40. <if test="productIcons != null">product_icons,</if>
  41. <if test="productTypeIds != null">product_type_ids,</if>
  42. <if test="productBidPrice != null">product_bid_price,</if>
  43. <if test="productSellPrice != null">product_sell_price,</if>
  44. </trim>
  45. <trim prefix="values (" suffix=")" suffixOverrides=",">
  46. <if test="id != null">#{id},</if>
  47. <if test="productState != null">#{productState},</if>
  48. <if test="productName != null">#{productName},</if>
  49. <if test="productIcons != null">#{productIcons},</if>
  50. <if test="productTypeIds != null">#{productTypeIds},</if>
  51. <if test="productBidPrice != null">#{productBidPrice},</if>
  52. <if test="productSellPrice != null">#{productSellPrice},</if>
  53. </trim>
  54. </insert>
  55. <update id="updateById" parameterType="com.example.entity.Product">
  56. update product
  57. <set>
  58. <if test="productState != null">
  59. product_state = #{productState},
  60. </if>
  61. <if test="productName != null">
  62. product_name = #{productName},
  63. </if>
  64. <if test="productIcons != null">
  65. product_icons = #{productIcons},
  66. </if>
  67. <if test="productIds != null">
  68. product_type_ids = #{productTypeIds},
  69. </if>
  70. <if test="productBidPrice != null">
  71. product_bid_price = #{productBidPrice},
  72. </if>
  73. <if test="productSellPrice != null">
  74. product_sell_price = #{productSellPrice},
  75. </if>
  76. </set>
  77. where id = #{id}
  78. </update>
  79. </mapper>