注解使用

1.@Secured

角色判断

1.1 开启注解

App启动类中加入注解

@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)

1.2 controller层下

@PostMapping("/toIndex")
@Secured("ROLE_aaa")     //角色判断
public String toIndex(){
    return "redirect:index.html";
}

2.@PreAuthorize

方法执行前使用access表达式判断

2.1 开启注解

2.2 controller层下

@PostMapping("/toIndex")
@PreAuthorize("hasRole('aaa')")//方法执行前判断
public String toIndex(){
    return "redirect:index.html";
}
posted @ 2023-01-17 16:42  lwx_R  阅读(25)  评论(0)    收藏  举报