我有 Spring MVC REST channel :
@Controller
@RequestMapping("/rest")
public class REST {
我有我的方法:
@RequestMapping(value = "/doSomething")
public @ResponseBody DoSomethingResultDTO doSomething(
@RequestBody DoSomethingRequestDTO)
现在我需要登录的用户名。通常我可以通过方法来完成
HttpServletRequest.getUserPrincipal()
但是这里怎么得到呢?我有 header (@RequestHeader
) 甚至 cookie (@CookieValue
) 的注释。但是如何在我的方法中获取 Principal
?
最佳答案
您可以将 Principal 对象注入(inject)到您的 Controller 处理程序方法中
@RequestMapping(value = "/doSomething")
public @ResponseBody DoSomethingResultDTO doSomething(
@RequestBody DoSomethingRequestDTO, Principal principal)
关于java - 如何在 Spring MVC REST channel 中获取登录的用户名/主体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17720488/