UserInfoController.java
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.xkl.controller;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
import com.xkl.domain.User;
import com.xkl.model.ResultModel;
import com.xkl.repository.UserRepository;
import com.xkl.security.AntiXSS;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by win7 on 2016/10/19.
*/
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
@Autowired
private UserRepository userRepository;
@RequestMapping(method = RequestMethod.GET)
@Authorization
@ApiOperation(value = "获取用户昵称")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> getUserNickName(@CurrentUser User user) {
String dickName=user.getNickname();
return new ResponseEntity<>(ResultModel.ok(dickName), HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.PUT)
@Authorization
@AntiXSS
@ApiOperation(value = "修改用户昵称")
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> modUserNickName(@CurrentUser User user,@RequestParam String userNickName) {
Assert.notNull(userNickName, "userDickName can not be empty");
user.setNickname(userNickName);
userRepository.save(user);
return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
}
}