UserMapper.xml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.fdkankan.user.mapper.IUserMapper">
  4. <resultMap id="resultMap" type="com.fdkankan.user.entity.User">
  5. <id column="id" jdbcType="VARCHAR" property="id" />
  6. <result column="head" jdbcType="VARCHAR" property="head" />
  7. <result column="password" jdbcType="VARCHAR" property="password" />
  8. <result column="email" jdbcType="VARCHAR" property="email" />
  9. <result column="register_time" jdbcType="TIMESTAMP" property="registerTime" />
  10. <result column="user_name" jdbcType="VARCHAR" property="userName" />
  11. <result column="nick_name" jdbcType="VARCHAR" property="nickName" />
  12. <result column="status" jdbcType="INTEGER" property="status" />
  13. <result column="is_notice" jdbcType="INTEGER" property="isNotice" />
  14. <result column="organization_name" jdbcType="VARCHAR" property="organizationName" />
  15. <result column="main_page" jdbcType="VARCHAR" property="mainPage" />
  16. <result column="country" jdbcType="VARCHAR" property="country" />
  17. <result column="province" jdbcType="VARCHAR" property="province" />
  18. <result column="city" jdbcType="VARCHAR" property="city" />
  19. <result column="download_num_total" jdbcType="INTEGER" property="downloadNumTotal" />
  20. <result column="download_num" jdbcType="INTEGER" property="downloadNum" />
  21. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  22. <result column="rec_status" jdbcType="VARCHAR" property="recStatus" />
  23. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  24. <result column="tb_status" jdbcType="INTEGER" property="tbStatus" />
  25. </resultMap>
  26. <sql id="columnList">
  27. id,head,password,email,register_time,user_name,nick_name,status,is_notice,organization_name,main_page,country,province,city,download_num_total,download_num,create_time,rec_status,update_time,tb_status </sql>
  28. <insert id="insert" useGeneratedKeys="true" keyProperty="entity.id">
  29. INSERT INTO ${tableName} (
  30. head, password, email, register_time, user_name, nick_name, status, is_notice, organization_name, main_page, country, province, city, download_num_total, download_num, rec_status
  31. ) VALUES (
  32. #{entity.head}, #{entity.password}, #{entity.email}, #{entity.registerTime}, #{entity.userName}, #{entity.nickName}, #{entity.status}, #{entity.isNotice}, #{entity.organizationName}, #{entity.mainPage}, #{entity.country}, #{entity.province}, #{entity.city}, #{entity.downloadNumTotal}, #{entity.downloadNum}, #{entity.recStatus}
  33. ) </insert>
  34. <insert id="insertByBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id" >
  35. INSERT INTO ${tableName} (
  36. head, password, email, register_time, user_name, nick_name, status, is_notice, organization_name, main_page, country, province, city, download_num_total, download_num, rec_status
  37. ) VALUES
  38. <foreach collection="list" item="entity" index="index" separator=",">
  39. (#{entity.head}, #{entity.password}, #{entity.email}, #{entity.registerTime}, #{entity.userName}, #{entity.nickName}, #{entity.status}, #{entity.isNotice}, #{entity.organizationName}, #{entity.mainPage}, #{entity.country}, #{entity.province}, #{entity.city}, #{entity.downloadNumTotal}, #{entity.downloadNum}, #{entity.recStatus})
  40. </foreach>
  41. </insert>
  42. <update id="update" parameterType="java.util.List" >
  43. <foreach collection="list" item="entity" index="index" separator=";">
  44. UPDATE ${tableName} SET
  45. head=#{entity.head}, password=#{entity.password}, email=#{entity.email}, register_time=#{entity.registerTime}, user_name=#{entity.userName}, nick_name=#{entity.nickName}, status=#{entity.status}, is_notice=#{entity.isNotice}, organization_name=#{entity.organizationName}, main_page=#{entity.mainPage}, country=#{entity.country}, province=#{entity.province}, city=#{entity.city}, download_num_total=#{entity.downloadNumTotal}, download_num=#{entity.downloadNum}, rec_status=#{entity.recStatus}, tb_status=#{entity.tbStatus}
  46. WHERE
  47. id = #{entity.id}
  48. </foreach>
  49. </update>
  50. <update id="updateByBatch" >
  51. UPDATE ${tableName} SET
  52. ${field}
  53. <where>
  54. <foreach collection="condition" index="key" item="value">
  55. ${value} ${key}
  56. </foreach>
  57. </where>
  58. </update>
  59. <select id="getById" parameterType="java.lang.Integer" resultMap="resultMap">
  60. select
  61. <include refid="columnList" />
  62. from ${tableName}
  63. where id = #{id}
  64. </select>
  65. <select id="getOne" parameterType="java.util.Map" resultMap="resultMap">
  66. select
  67. <if test="field == null">
  68. <include refid="columnList" />
  69. </if>
  70. <if test="field != null">
  71. ${field}
  72. </if>
  73. from ${tableName}
  74. <where>
  75. <foreach collection="condition" index="key" item="value">
  76. ${value} ${key}
  77. </foreach>
  78. </where>
  79. limit 1;
  80. </select>
  81. <select id="getCount" parameterType="java.util.Map" resultType="java.lang.Integer">
  82. select
  83. count(id)
  84. from ${tableName}
  85. <where>
  86. <foreach collection="condition" index="key" item="value">
  87. ${value} ${key}
  88. </foreach>
  89. </where>
  90. </select>
  91. <!-- 这部分为根据传递参数,自动生成SQL -->
  92. <select id="getList" parameterType="java.util.Map" resultMap="resultMap">
  93. select
  94. <if test="field == null">
  95. <include refid="columnList" />
  96. </if>
  97. <if test="field != null">
  98. ${field}
  99. </if>
  100. from ${tableName}
  101. <where>
  102. <foreach collection="condition" index="key" item="value">
  103. ${value} ${key}
  104. </foreach>
  105. </where>
  106. <if test="order != null">
  107. order by ${order}
  108. </if>
  109. <if test="limit != 0">
  110. <if test="offset != 0">
  111. limit ${offset}, ${limit}
  112. </if>
  113. <if test="offset == 0">
  114. limit ${limit}
  115. </if>
  116. </if>
  117. </select>
  118. <!-- 判断表格是否存在,如果不存在可以配合createTable使用,用于动态创建表格 -->
  119. <select id="existTable" parameterType="String" resultType="java.lang.Integer">
  120. select count(table_name) from information_schema.TABLES WHERE table_name=#{tableName} ;
  121. </select>
  122. <update id="createTable" parameterType="String">
  123. <!-- 这里是创建表格的SQL,复制过来,表名作为参数传递 -->
  124. <!-- create table ${tableName} ( // 表名要这样写 -->
  125. </update>
  126. </mapper>