RecordsMapper.xml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. <if test="userId != null"> and records.user_id = #{userId}</if>
  18. </where>
  19. order by id desc
  20. </select>
  21. <select id="selectById" resultType="com.example.entity.Records">
  22. select
  23. <include refid="Base_Column_List" />
  24. from records
  25. where id = #{id}
  26. </select>
  27. <delete id="deleteById">
  28. delete from records
  29. where id = #{id}
  30. </delete>
  31. <insert id="insert" parameterType="com.example.entity.Records" useGeneratedKeys="true">
  32. insert into records
  33. <trim prefix="(" suffix=")" suffixOverrides=",">
  34. <if test="id != null">id,</if>
  35. <if test="content != null">content,</if>
  36. <if test="money != null">money,</if>
  37. <if test="userId != null">user_id,</if>
  38. <if test="time != null">time,</if>
  39. <if test="type != null">type,</if>
  40. </trim>
  41. <trim prefix="values (" suffix=")" suffixOverrides=",">
  42. <if test="id != null">#{id},</if>
  43. <if test="content != null">#{content},</if>
  44. <if test="money != null">#{money},</if>
  45. <if test="userId != null">#{userId},</if>
  46. <if test="time != null">#{time},</if>
  47. <if test="type != null">#{type},</if>
  48. </trim>
  49. </insert>
  50. <update id="updateById" parameterType="com.example.entity.Records">
  51. update records
  52. <set>
  53. <if test="content != null">
  54. content = #{content},
  55. </if>
  56. <if test="money != null">
  57. money = #{money},
  58. </if>
  59. <if test="userId != null">
  60. user_id = #{userId},
  61. </if>
  62. <if test="time != null">
  63. time = #{time},
  64. </if>
  65. <if test="type != null">
  66. type = #{type},
  67. </if>
  68. </set>
  69. where id = #{id}
  70. </update>
  71. </mapper>