2323import org .springframework .beans .factory .annotation .Autowired ;
2424import org .springframework .beans .factory .annotation .Value ;
2525import org .springframework .context .annotation .PropertySource ;
26+ import org .springframework .http .HttpStatus ;
2627import org .springframework .validation .annotation .Validated ;
2728import org .springframework .web .bind .annotation .*;
2829
2930import javax .servlet .http .HttpServletResponse ;
30- import java .text .SimpleDateFormat ;
3131import java .util .*;
3232
3333/**
@@ -63,6 +63,10 @@ public UserController(IUserService userService) {
6363 @ GetMapping
6464 @ RequiresPermissions (logical = Logical .AND , value = {"user:view" })
6565 public ResponseBean user (@ Validated BaseDto baseDto ){
66+ if (baseDto .getPage () == null || baseDto .getRows () == null ){
67+ baseDto .setPage (1 );
68+ baseDto .setRows (10 );
69+ }
6670 PageHelper .startPage (baseDto .getPage (), baseDto .getRows ());
6771 List <UserDto > userDtos = userService .selectAll ();
6872 PageInfo <UserDto > selectPage = new PageInfo <UserDto >(userDtos );
@@ -72,7 +76,7 @@ public ResponseBean user(@Validated BaseDto baseDto){
7276 Map <String , Object > result = new HashMap <String , Object >(16 );
7377 result .put ("count" , selectPage .getTotal ());
7478 result .put ("data" , selectPage .getList ());
75- return new ResponseBean (200 , "查询成功(Query was successful)" , result );
79+ return new ResponseBean (HttpStatus . OK . value () , "查询成功(Query was successful)" , result );
7680 }
7781
7882 /**
@@ -103,7 +107,7 @@ public ResponseBean online(){
103107 if (userDtos == null || userDtos .size () <= 0 ){
104108 throw new CustomException ("查询失败(Query Failure)" );
105109 }
106- return new ResponseBean (200 , "查询成功(Query was successful)" , userDtos );
110+ return new ResponseBean (HttpStatus . OK . value () , "查询成功(Query was successful)" , userDtos );
107111 }
108112
109113 /**
@@ -137,7 +141,7 @@ public ResponseBean login(@Validated(UserLoginValidGroup.class) @RequestBody Use
137141 String token = JwtUtil .sign (userDto .getAccount (), currentTimeMillis );
138142 httpServletResponse .setHeader ("Authorization" , token );
139143 httpServletResponse .setHeader ("Access-Control-Expose-Headers" , "Authorization" );
140- return new ResponseBean (200 , "登录成功(Login Success.)" , null );
144+ return new ResponseBean (HttpStatus . OK . value () , "登录成功(Login Success.)" , null );
141145 } else {
142146 throw new CustomUnauthorizedException ("帐号或密码错误(Account or Password Error.)" );
143147 }
@@ -155,9 +159,9 @@ public ResponseBean article() {
155159 Subject subject = SecurityUtils .getSubject ();
156160 // 登录了返回true
157161 if (subject .isAuthenticated ()) {
158- return new ResponseBean (200 , "您已经登录了(You are already logged in)" , null );
162+ return new ResponseBean (HttpStatus . OK . value () , "您已经登录了(You are already logged in)" , null );
159163 } else {
160- return new ResponseBean (200 , "你是游客(You are guest)" , null );
164+ return new ResponseBean (HttpStatus . OK . value () , "你是游客(You are guest)" , null );
161165 }
162166 }
163167
@@ -171,7 +175,7 @@ public ResponseBean article() {
171175 @ GetMapping ("/article2" )
172176 @ RequiresAuthentication
173177 public ResponseBean requireAuth () {
174- return new ResponseBean (200 , "您已经登录了(You are already logged in)" , null );
178+ return new ResponseBean (HttpStatus . OK . value () , "您已经登录了(You are already logged in)" , null );
175179 }
176180
177181 /**
@@ -188,7 +192,7 @@ public ResponseBean findById(@PathVariable("id") Integer id){
188192 if (userDto == null ){
189193 throw new CustomException ("查询失败(Query Failure)" );
190194 }
191- return new ResponseBean (200 , "查询成功(Query was successful)" , userDto );
195+ return new ResponseBean (HttpStatus . OK . value () , "查询成功(Query was successful)" , userDto );
192196 }
193197
194198 /**
@@ -219,7 +223,7 @@ public ResponseBean add(@Validated(UserEditValidGroup.class) @RequestBody UserDt
219223 if (count <= 0 ){
220224 throw new CustomException ("新增失败(Insert Failure)" );
221225 }
222- return new ResponseBean (200 , "新增成功(Insert Success)" , userDto );
226+ return new ResponseBean (HttpStatus . OK . value () , "新增成功(Insert Success)" , userDto );
223227 }
224228
225229 /**
@@ -254,7 +258,7 @@ public ResponseBean update(@Validated(UserEditValidGroup.class) @RequestBody Use
254258 if (count <= 0 ){
255259 throw new CustomException ("更新失败(Update Failure)" );
256260 }
257- return new ResponseBean (200 , "更新成功(Update Success)" , userDto );
261+ return new ResponseBean (HttpStatus . OK . value () , "更新成功(Update Success)" , userDto );
258262 }
259263
260264 /**
@@ -271,7 +275,7 @@ public ResponseBean delete(@PathVariable("id") Integer id){
271275 if (count <= 0 ){
272276 throw new CustomException ("删除失败,ID不存在(Deletion Failed. ID does not exist.)" );
273277 }
274- return new ResponseBean (200 , "删除成功(Delete Success)" , null );
278+ return new ResponseBean (HttpStatus . OK . value () , "删除成功(Delete Success)" , null );
275279 }
276280
277281 /**
@@ -287,7 +291,7 @@ public ResponseBean deleteOnline(@PathVariable("id") Integer id){
287291 UserDto userDto = userService .selectByPrimaryKey (id );
288292 if (JedisUtil .exists (Constant .PREFIX_SHIRO_REFRESH_TOKEN + userDto .getAccount ())){
289293 if (JedisUtil .delKey (Constant .PREFIX_SHIRO_REFRESH_TOKEN + userDto .getAccount ()) > 0 ){
290- return new ResponseBean (200 , "剔除成功(Delete Success)" , null );
294+ return new ResponseBean (HttpStatus . OK . value () , "剔除成功(Delete Success)" , null );
291295 }
292296 }
293297 throw new CustomException ("剔除失败,Account不存在(Deletion Failed. Account does not exist.)" );
0 commit comments