RecordsMapper.xml 2.4 KB

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