增加LoginUserContextHolder获取当前登录人对象
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.zlt.controller;
|
||||
|
||||
import com.central.common.annotation.LoginUser;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.model.SysUser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -16,11 +17,22 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class TestController {
|
||||
/**
|
||||
* 通过 @LoginUser 获取当前登录人
|
||||
*/
|
||||
@GetMapping("/test/auth")
|
||||
public String auth(@LoginUser SysUser user) {
|
||||
return "auth:" + user.getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 LoginUserContextHolder 获取当前登录人
|
||||
*/
|
||||
@GetMapping("/test/auth2")
|
||||
public String auth() {
|
||||
return "auth2:" + LoginUserContextHolder.getUser().getUsername();
|
||||
}
|
||||
|
||||
@GetMapping("/test/notAuth")
|
||||
public String notAuth() {
|
||||
return "notAuth:ok";
|
||||
|
||||
Reference in New Issue
Block a user