@preAuthorize注解:执行之前判断权限,常用

@postAuthorize注解:执行之后判断权限,不常用,使用方法同@preAuthorize

添加角色权限
在SpringsecuritydemoApplication中添加

//启用Spring Security注解
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)

controller方法类中
LoginController.java

//PreAuthorize的表达式允许ROLE_开头,也可以不以ROLE_开头,配置类不允许ROLE_开头
@PreAuthorize("hasRole('abc')")

位置截图: