CommentMapper.xml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.CommentMapper">
  6. <sql id="Base_Column_List">
  7. id,content,star,user_id,accept_id,order_id,time
  8. </sql>
  9. <select id="selectAll" resultType="com.example.entity.Comment">
  10. select
  11. comment.*, user1.name as userName, user2.name as acceptName, orders.order_no as orderNo
  12. from comment
  13. left join user user1
  14. on comment.user_id = user1.id
  15. left join user user2
  16. on comment.accept_id = user2.id
  17. left join orders
  18. on comment.order_id = orders.id
  19. <where>
  20. <if test="content != null"> and comment.content like concat('%', #{content}, '%')</if>
  21. <if test="userName != null"> and user1.name like concat('%', #{userName}, '%')</if>
  22. <if test="acceptName != null"> and user2.name like concat('%', #{acceptName}, '%')</if>
  23. <if test="orderNo != null"> and orders.order_no like concat('%', #{orderNo}, '%')</if>
  24. </where>
  25. order by id desc
  26. </select>
  27. <select id="selectById" resultType="com.example.entity.Comment">
  28. select
  29. <include refid="Base_Column_List" />
  30. from comment
  31. where id = #{id}
  32. </select>
  33. <delete id="deleteById">
  34. delete from comment
  35. where id = #{id}
  36. </delete>
  37. <insert id="insert" parameterType="com.example.entity.Comment" useGeneratedKeys="true">
  38. insert into comment
  39. <trim prefix="(" suffix=")" suffixOverrides=",">
  40. <if test="id != null">id,</if>
  41. <if test="content != null">content,</if>
  42. <if test="star != null">star,</if>
  43. <if test="userId != null">user_id,</if>
  44. <if test="acceptId != null">accept_id,</if>
  45. <if test="orderId != null">order_id,</if>
  46. <if test="time != null">time,</if>
  47. </trim>
  48. <trim prefix="values (" suffix=")" suffixOverrides=",">
  49. <if test="id != null">#{id},</if>
  50. <if test="content != null">#{content},</if>
  51. <if test="star != null">#{star},</if>
  52. <if test="userId != null">#{userId},</if>
  53. <if test="acceptId != null">#{acceptId},</if>
  54. <if test="orderId != null">#{orderId},</if>
  55. <if test="time != null">#{time},</if>
  56. </trim>
  57. </insert>
  58. <update id="updateById" parameterType="com.example.entity.Comment">
  59. update comment
  60. <set>
  61. <if test="content != null">
  62. content = #{content},
  63. </if>
  64. <if test="star != null">
  65. star = #{star},
  66. </if>
  67. <if test="userId != null">
  68. user_id = #{userId},
  69. </if>
  70. <if test="acceptId != null">
  71. accept_id = #{acceptId},
  72. </if>
  73. <if test="orderId != null">
  74. order_id = #{orderId},
  75. </if>
  76. <if test="time != null">
  77. time = #{time},
  78. </if>
  79. </set>
  80. where id = #{id}
  81. </update>
  82. </mapper>