167b6f94f00b1c53d68e86bcf1ff466153459f17.svn-base 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC
  4. "-//mybatis.org//DTD Mapper 3.0//EN"
  5. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  6. <!-- 命名,每一个映射对象不一样
  7. namespace:必须与对应的接口全类名一致
  8. -->
  9. <mapper namespace="com.iamberry.app.mapper.UserMapper">
  10. <sql id="userAttribute">
  11. id,
  12. username,
  13. password,
  14. token,
  15. display_name,
  16. display_picture,
  17. created_on,
  18. ext_open_id,
  19. ext_name,
  20. ext_type,
  21. location,
  22. baby_nickname,
  23. baby_dob,
  24. baby_gender,
  25. status_ ,
  26. user_tel userTel
  27. </sql>
  28. <resultMap type="User" id="userMap">
  29. <id property="id" column="id"/>
  30. <result property="username" column="username"/>
  31. <result property="password" column="password"/>
  32. <result property="token" column="token"/>
  33. <result property="display_name" column="display_name"/>
  34. <result property="display_picture" column="display_picture"/>
  35. <result property="created_on" column="created_on"/>
  36. <result property="ext_open_id" column="ext_open_id"/>
  37. <result property="ext_name" column="ext_name"/>
  38. <result property="ext_type" column="ext_type"/>
  39. <result property="location" column="location"/>
  40. <result property="baby_nickname" column="baby_nickname"/>
  41. <result property="baby_dob" column="baby_dob"/>
  42. <result property="baby_gender" column="baby_gender"/>
  43. <result property="status_" column="status_"/>
  44. </resultMap>
  45. <!-- 根据id查询user所有信息 -->
  46. <select id="selectUserById" parameterType="java.lang.Long" resultMap="userMap">
  47. SELECT
  48. <include refid="userAttribute" />
  49. FROM USER WHERE ID = #{0}
  50. </select>
  51. <!-- 根据username查询user所有信息 -->
  52. <select id="selectUserByUsername" parameterType="java.lang.String" resultMap="userMap">
  53. SELECT <include refid="userAttribute" /> FROM USER WHERE USERNAME = #{0}
  54. </select>
  55. <!-- 通过ext_open_id查询user所有信息 -->
  56. <select id="selectUserByExtOpenId" parameterType="java.lang.String" resultMap="userMap">
  57. SELECT <include refid="userAttribute" /> FROM USER WHERE EXT_OPEN_ID = #{0}
  58. </select>
  59. <!-- 添加用户信息到user表中 -->
  60. <insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="id">
  61. INSERT INTO USER
  62. (
  63. USERNAME,PASSWORD,TOKEN,DISPLAY_NAME,DISPLAY_PICTURE,
  64. CREATED_ON,EXT_OPEN_ID,EXT_NAME,EXT_TYPE,
  65. LOCATION,BABY_NICKNAME,BABY_DOB,BABY_GENDER,STATUS_,USER_TEL)
  66. VALUES
  67. (
  68. #{username},#{password},#{token},#{display_name},#{display_picture},
  69. NOW(),#{ext_open_id},#{ext_name},#{ext_type},
  70. #{location},#{baby_nickname},#{baby_dob},#{baby_gender},#{status_}, #{userTel}
  71. )
  72. </insert>
  73. <!-- 根据id修改user表数据 -->
  74. <update id="updateUser" parameterType="User">
  75. UPDATE USER
  76. <set>
  77. <if test="username != null and username != ''">
  78. USERNAME = #{username},
  79. </if>
  80. <if test="password != null and password != ''">
  81. PASSWORD = #{password},
  82. </if>
  83. <if test="token != null and token != ''">
  84. TOKEN = #{token},
  85. </if>
  86. <if test="display_name != null and display_name != ''">
  87. DISPLAY_NAME = #{display_name},
  88. </if>
  89. <if test="display_picture != null and display_picture != ''">
  90. DISPLAY_PICTURE = #{display_picture},
  91. </if>
  92. <if test="ext_open_id != null and ext_open_id != ''">
  93. EXT_OPEN_ID = #{ext_open_id},
  94. </if>
  95. <if test="ext_name != null and ext_name != ''">
  96. EXT_NAME = #{ext_name},
  97. </if>
  98. <if test="ext_type != null and ext_type != ''">
  99. EXT_TYPE = #{ext_type},
  100. </if>
  101. <if test="location != null and location != ''">
  102. LOCATION = #{location},
  103. </if>
  104. <if test="baby_nickname != null and baby_nickname != ''">
  105. BABY_NICKNAME = #{baby_nickname},
  106. </if>
  107. <if test="baby_dob != null and baby_dob != ''">
  108. BABY_DOB = #{baby_dob},
  109. </if>
  110. <if test="baby_gender != null and baby_gender != ''">
  111. BABY_GENDER = #{baby_gender},
  112. </if>
  113. <if test="status_ != null and status_ != ''">
  114. STATUS_ = #{status_},
  115. </if>
  116. <if test="userTel != null and userTel != ''">
  117. USER_TEL = #{userTel}
  118. </if>
  119. </set>
  120. WHERE
  121. ID = #{id}
  122. </update>
  123. <!-- 根据id修改user表的个人头像 -->
  124. <update id="updateDisplayPicture">
  125. UPDATE USER SET DISPLAY_PICTURE = #{0} WHERE ID = #{1}
  126. </update>
  127. <!-- 根据用户名和密码查询用户表信息 -->
  128. <select id="validateUser" parameterType="java.lang.String" resultMap="userMap">
  129. SELECT <include refid="userAttribute"/> FROM USER WHERE USERNAME=#{0} AND PASSWORD=#{1}
  130. </select>
  131. <!-- 通过id修改用户表密码 -->
  132. <update id="changePassword">
  133. UPDATE USER SET PASSWORD=#{1} WHERE ID=#{0}
  134. </update>
  135. <!-- 通过token查询user表所有信息 -->
  136. <select id="selectUserByToken" parameterType="java.lang.String" resultMap="userMap">
  137. SELECT <include refid="userAttribute"/> FROM USER WHERE TOKEN=#{0}
  138. </select>
  139. <!-- 根据id修改token值 -->
  140. <update id="updateUserToken">
  141. UPDATE USER SET TOKEN=#{0} WHERE ID=#{1}
  142. </update>
  143. <!-- 根据id修改user表的用户名 -->
  144. <update id="updateUserName">
  145. UPDATE USER SET USERNAME=#{0} WHERE ID=#{1}
  146. </update>
  147. <!-- 通过key_查询sys_config表数据 -->
  148. <select id="selectConfig" parameterType="java.lang.String" resultType="String">
  149. SELECT VALUE_ FROM SYS_CONFIG WHERE KEY_ = #{0}
  150. </select>
  151. <!-- USER_AVATOR表中添加数据 -->
  152. <insert id="insertUserAvator">
  153. INSERT INTO USER_AVATOR (USER_ID, AVATOR) VALUE (#{0}, #{1})
  154. </insert>
  155. <!-- 通过user_id修改USER_AVATOR表数据 -->
  156. <update id="updateUserAvator">
  157. UPDATE USER_AVATOR SET AVATOR = #{1} WHERE USER_ID = #{0}
  158. </update>
  159. <!-- 根据user_id查询USER_AVATOR表数据 -->
  160. <select id="selectUserAvator" parameterType="java.lang.Long" resultType="java.lang.String">
  161. SELECT avator FROM USER_AVATOR WHERE USER_ID = #{id}
  162. </select>
  163. <select id="getAll" parameterType="java.util.Map" resultMap="userMap">
  164. SELECT
  165. <include refid="userAttribute"/>
  166. FROM
  167. USER
  168. LIMIT
  169. #{start}, #{end}
  170. </select>
  171. </mapper>