思路:使用拦截器和自定义注解,在拦截器中对请求用户的身份类型进行判断。
1、自定义注解
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author xen
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface PremTwo {
// 当为空时,可以使用uri进行转换,/sys/user/page==>sys:user:page
String[] value();
}
2、在控制器方法中使用自定义注解
import com.nine.realestateregistration.auth.PremTwo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author: xen
* @create: 2023-05-08 12:56
**/
@Controller
@RequestMapping("/test")
public class TestController {
@GetMapping("/t1")
@PremTwo({