@Secured
用户具有某个角色,可以访问方法
- 启动类(配置类)开启注解
@SpringBootApplication
@MapperScan("com.ljy.security.mapper")
//开启注解
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityApplication {
public static void main(String[] args) {
SpringApplication.run(SecurityApplication.class, args);
}
}
- 在controller的方法上面来使用注解,设置角色
@GetMapping("update")
//只有具有此角色才能访问此方法
@Secured({
"ROLE_sale","ROLE_mannger"})
public String update() {
return "hello update";
}