Jakarta ee 如何在@Preauthorize中使用path变量

Jakarta ee 如何在@Preauthorize中使用path变量,jakarta-ee,spring-security,pre-authentication,Jakarta Ee,Spring Security,Pre Authentication,我需要将path变量作为参数传递给预授权 @RequestMapping(value="/page/{cmd}", method = RequestMethod.GET) @PreAuthorize("hasRole(#cmd)") public void method(@PathVariable String cmd, HttpServletRequest request, HttpServletResponse response){ // my stuff }

我需要将path变量作为参数传递给预授权

    @RequestMapping(value="/page/{cmd}", method = RequestMethod.GET)
    @PreAuthorize("hasRole(#cmd)") 
     public void method(@PathVariable String cmd, HttpServletRequest request,  HttpServletResponse response){
// my stuff
}

它不起作用。有人能建议我如何在预授权中使用path变量吗?

Spring Security的
@PreAuthorize
用于授权对方法的访问。它对SpringMVC了解不多,尤其是它的
@RequestMapping
注释

#cmd
这样的名称将引用方法参数,而
cmd
参数为空。将其更改为:

@PathVariable("cmd") String cmd
这样,
cmd
路径变量将绑定到
cmd
方法参数,然后该参数将被
@PreAuthorize
中的
#cmd
绑定