NoticeMapper.xml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.NoticeMapper">
  6. <sql id="Base_Column_List">
  7. id,title,content,time,user
  8. </sql>
  9. <select id="selectAll" resultType="com.example.entity.Notice">
  10. select
  11. <include refid="Base_Column_List" />
  12. from notice
  13. <where>
  14. <if test="id != null"> and id= #{id}</if>
  15. <if test="title != null"> and title like concat('%', #{title}, '%')</if>
  16. <if test="content != null"> and content= #{content}</if>
  17. <if test="time != null"> and time= #{time}</if>
  18. <if test="user != null"> and user= #{user}</if>
  19. </where>
  20. order by id desc
  21. </select>
  22. <select id="selectById" resultType="com.example.entity.Notice">
  23. select
  24. <include refid="Base_Column_List" />
  25. from notice
  26. where id = #{id}
  27. </select>
  28. <delete id="deleteById">
  29. delete from notice
  30. where id = #{id}
  31. </delete>
  32. <insert id="insert" parameterType="com.example.entity.Notice" useGeneratedKeys="true">
  33. insert into notice
  34. <trim prefix="(" suffix=")" suffixOverrides=",">
  35. <if test="id != null">id,</if>
  36. <if test="title != null">title,</if>
  37. <if test="content != null">content,</if>
  38. <if test="time != null">time,</if>
  39. <if test="user != null">user,</if>
  40. </trim>
  41. <trim prefix="values (" suffix=")" suffixOverrides=",">
  42. <if test="id != null">#{id},</if>
  43. <if test="title != null">#{title},</if>
  44. <if test="content != null">#{content},</if>
  45. <if test="time != null">#{time},</if>
  46. <if test="user != null">#{user},</if>
  47. </trim>
  48. </insert>
  49. <update id="updateById" parameterType="com.example.entity.Notice">
  50. update notice
  51. <set>
  52. <if test="title != null">
  53. title = #{title},
  54. </if>
  55. <if test="content != null">
  56. content = #{content},
  57. </if>
  58. <if test="time != null">
  59. time = #{time},
  60. </if>
  61. <if test="user != null">
  62. user = #{user},
  63. </if>
  64. </set>
  65. where id = #{id}
  66. </update>
  67. </mapper>