正在显示
5 个修改的文件
包含
44 行增加
和
19 行删除
@@ -11,6 +11,8 @@ import com.tianbo.warehouse.model.UserRole; | @@ -11,6 +11,8 @@ import com.tianbo.warehouse.model.UserRole; | ||
11 | import com.tianbo.warehouse.security.CustomUserDetailService; | 11 | import com.tianbo.warehouse.security.CustomUserDetailService; |
12 | import com.tianbo.warehouse.security.filter.JwtTokenUtil; | 12 | import com.tianbo.warehouse.security.filter.JwtTokenUtil; |
13 | import com.tianbo.warehouse.service.UserService; | 13 | import com.tianbo.warehouse.service.UserService; |
14 | +import com.tianbo.warehouse.service.validated.InsertUser; | ||
15 | +import com.tianbo.warehouse.service.validated.UpdateUser; | ||
14 | import com.tianbo.warehouse.util.RedisUtils; | 16 | import com.tianbo.warehouse.util.RedisUtils; |
15 | import io.swagger.annotations.Api; | 17 | import io.swagger.annotations.Api; |
16 | import io.swagger.annotations.ApiImplicitParam; | 18 | import io.swagger.annotations.ApiImplicitParam; |
@@ -20,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -20,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
20 | import org.springframework.security.core.context.SecurityContextHolder; | 22 | import org.springframework.security.core.context.SecurityContextHolder; |
21 | import org.springframework.security.core.userdetails.UserDetails; | 23 | import org.springframework.security.core.userdetails.UserDetails; |
22 | import org.springframework.validation.BindingResult; | 24 | import org.springframework.validation.BindingResult; |
25 | +import org.springframework.validation.annotation.Validated; | ||
23 | import org.springframework.web.bind.annotation.*; | 26 | import org.springframework.web.bind.annotation.*; |
24 | 27 | ||
25 | import javax.servlet.http.HttpServletRequest; | 28 | import javax.servlet.http.HttpServletRequest; |
@@ -68,7 +71,7 @@ public class UserController { | @@ -68,7 +71,7 @@ public class UserController { | ||
68 | 71 | ||
69 | @LogAnnotation(moduleName = "用户管理",operate = "用户编辑") | 72 | @LogAnnotation(moduleName = "用户管理",operate = "用户编辑") |
70 | @PutMapping("/edit") | 73 | @PutMapping("/edit") |
71 | - public ResultJson updateUserById(@RequestBody @Valid USERS user){ | 74 | + public ResultJson updateUserById(@Validated(UpdateUser.class) @RequestBody USERS user){ |
72 | int i = userService.updateByPrimaryKeySelective(user); | 75 | int i = userService.updateByPrimaryKeySelective(user); |
73 | ResultJson resultJson = new ResultJson(); | 76 | ResultJson resultJson = new ResultJson(); |
74 | return i==1 ? new ResultJson("200","success") :new ResultJson("500","update faild"); | 77 | return i==1 ? new ResultJson("200","success") :new ResultJson("500","update faild"); |
@@ -86,7 +89,7 @@ public class UserController { | @@ -86,7 +89,7 @@ public class UserController { | ||
86 | @UserPasswordMd5 | 89 | @UserPasswordMd5 |
87 | @LogAnnotation(moduleName = "用户管理",operate = "用户添加") | 90 | @LogAnnotation(moduleName = "用户管理",operate = "用户添加") |
88 | @PostMapping("/add") | 91 | @PostMapping("/add") |
89 | - public ResultJson addUser(@RequestBody @Valid USERS user, HttpServletRequest request, HttpServletResponse response, BindingResult bindingResult){ | 92 | + public ResultJson addUser(@RequestBody @Validated(InsertUser.class) USERS user, HttpServletRequest request, HttpServletResponse response, BindingResult bindingResult){ |
90 | 93 | ||
91 | if (bindingResult.hasErrors()){ | 94 | if (bindingResult.hasErrors()){ |
92 | String s = bindingResult.toString(); | 95 | String s = bindingResult.toString(); |
@@ -2,6 +2,8 @@ package com.tianbo.warehouse.model; | @@ -2,6 +2,8 @@ package com.tianbo.warehouse.model; | ||
2 | 2 | ||
3 | import com.alibaba.fastjson.annotation.JSONField; | 3 | import com.alibaba.fastjson.annotation.JSONField; |
4 | import com.alibaba.fastjson.serializer.SerializerFeature; | 4 | import com.alibaba.fastjson.serializer.SerializerFeature; |
5 | +import com.tianbo.warehouse.service.validated.InsertUser; | ||
6 | +import com.tianbo.warehouse.service.validated.UpdateUser; | ||
5 | import com.tianbo.warehouse.validate.CheckUserExist; | 7 | import com.tianbo.warehouse.validate.CheckUserExist; |
6 | import org.hibernate.validator.constraints.Length; | 8 | import org.hibernate.validator.constraints.Length; |
7 | import org.springframework.security.core.GrantedAuthority; | 9 | import org.springframework.security.core.GrantedAuthority; |
@@ -18,17 +20,17 @@ public class USERS implements UserDetails { | @@ -18,17 +20,17 @@ public class USERS implements UserDetails { | ||
18 | 20 | ||
19 | private static final long serialVersionUID = 1L; | 21 | private static final long serialVersionUID = 1L; |
20 | 22 | ||
21 | - @DecimalMin("1") | 23 | + @DecimalMin(value = "1",groups={InsertUser.class, UpdateUser.class}) |
22 | private Integer userId; | 24 | private Integer userId; |
23 | 25 | ||
24 | - @NotBlank(message="用户名不能为空") | ||
25 | - @Length(min = 5, max = 11, message = "username 长度必须在 {min} - {max} 之间") | ||
26 | - @CheckUserExist(message = "用户已存在") | 26 | + @NotBlank(message="用户名不能为空",groups={InsertUser.class, UpdateUser.class}) |
27 | + @Length(min = 5, max = 11, message = "username 长度必须在 {min} - {max} 之间",groups={InsertUser.class, UpdateUser.class}) | ||
28 | + @CheckUserExist(message = "用户已存在",groups=InsertUser.class) | ||
27 | private String username; | 29 | private String username; |
28 | 30 | ||
29 | - @NotNull | ||
30 | - @NotBlank(message="密码不能为空") | ||
31 | - @Length(min = 6, max = 22, message = "密码 长度必须在 {min} - {max} 之间") | 31 | + @NotNull(message="密码不能为null",groups=InsertUser.class) |
32 | + @NotBlank(message="密码不能为空",groups=InsertUser.class) | ||
33 | + @Length(min = 6, max = 22, message = "密码 长度必须在 {min} - {max} 之间",groups=InsertUser.class) | ||
32 | private String password; | 34 | private String password; |
33 | 35 | ||
34 | private Date birthday; | 36 | private Date birthday; |
@@ -275,4 +277,4 @@ public class USERS implements UserDetails { | @@ -275,4 +277,4 @@ public class USERS implements UserDetails { | ||
275 | } | 277 | } |
276 | return auths; | 278 | return auths; |
277 | } | 279 | } |
278 | -} | ||
280 | +} |
@@ -40,7 +40,7 @@ | @@ -40,7 +40,7 @@ | ||
40 | user_id, username, birthday, sex, address, state, mobilePhone,userFace, realName, email, age | 40 | user_id, username, birthday, sex, address, state, mobilePhone,userFace, realName, email, age |
41 | </sql> | 41 | </sql> |
42 | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | 42 | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > |
43 | - select | 43 | + select |
44 | <include refid="Base_Column_List" /> | 44 | <include refid="Base_Column_List" /> |
45 | from users | 45 | from users |
46 | where user_id = #{userId,jdbcType=INTEGER} | 46 | where user_id = #{userId,jdbcType=INTEGER} |
@@ -53,7 +53,9 @@ | @@ -53,7 +53,9 @@ | ||
53 | </select> | 53 | </select> |
54 | <select id="selectAllUser" resultMap="BaseResultMap" parameterType="com.tianbo.warehouse.model.USERS" > | 54 | <select id="selectAllUser" resultMap="BaseResultMap" parameterType="com.tianbo.warehouse.model.USERS" > |
55 | select | 55 | select |
56 | - <include refid="Base_Column_List" /> | 56 | +<!-- <include refid="Base_Column_List" />--> |
57 | + user_id, username, birthday, sex, address, state, mobilePhone, creatTime, | ||
58 | + updateTime, userFace, realName, email, age,company_id | ||
57 | from users | 59 | from users |
58 | WHERE 1=1 | 60 | WHERE 1=1 |
59 | <if test=" username != null" > | 61 | <if test=" username != null" > |
@@ -68,14 +70,14 @@ | @@ -68,14 +70,14 @@ | ||
68 | where user_id = #{userId,jdbcType=INTEGER} | 70 | where user_id = #{userId,jdbcType=INTEGER} |
69 | </delete> | 71 | </delete> |
70 | <insert id="insert" parameterType="com.tianbo.warehouse.model.USERS" > | 72 | <insert id="insert" parameterType="com.tianbo.warehouse.model.USERS" > |
71 | - insert into users (user_id, username, password, | ||
72 | - birthday, sex, address, | ||
73 | - state, mobilePhone, creatTime, | 73 | + insert into users (user_id, username, password, |
74 | + birthday, sex, address, | ||
75 | + state, mobilePhone, creatTime, | ||
74 | updateTime, userFace, realName, | 76 | updateTime, userFace, realName, |
75 | email, age) | 77 | email, age) |
76 | - values (#{userId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, | ||
77 | - #{birthday,jdbcType=TIMESTAMP}, #{sex,jdbcType=CHAR}, #{address,jdbcType=VARCHAR}, | ||
78 | - #{state,jdbcType=BIT}, #{mobilephone,jdbcType=VARCHAR}, #{creattime,jdbcType=TIMESTAMP}, | 78 | + values (#{userId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, |
79 | + #{birthday,jdbcType=TIMESTAMP}, #{sex,jdbcType=CHAR}, #{address,jdbcType=VARCHAR}, | ||
80 | + #{state,jdbcType=BIT}, #{mobilephone,jdbcType=VARCHAR}, #{creattime,jdbcType=TIMESTAMP}, | ||
79 | #{updatetime,jdbcType=TIMESTAMP}, #{userface,jdbcType=VARCHAR}, #{realname,jdbcType=VARCHAR}, | 81 | #{updatetime,jdbcType=TIMESTAMP}, #{userface,jdbcType=VARCHAR}, #{realname,jdbcType=VARCHAR}, |
80 | #{email,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER}) | 82 | #{email,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER}) |
81 | </insert> | 83 | </insert> |
@@ -228,4 +230,4 @@ | @@ -228,4 +230,4 @@ | ||
228 | age = #{age,jdbcType=INTEGER} | 230 | age = #{age,jdbcType=INTEGER} |
229 | where user_id = #{userId,jdbcType=INTEGER} | 231 | where user_id = #{userId,jdbcType=INTEGER} |
230 | </update> | 232 | </update> |
231 | -</mapper> | ||
233 | +</mapper> |
-
请 注册 或 登录 后发表评论