简体   繁体   中英

Path variable usage as annotation param

I've got simple spring mvc controller

@GetMapping("/{s}")
@PreAuthorize("@myMethod(s, Constant.WRITE")
public ResponseEntity<MyDto> getDto(
    @PathVariable("s") String s
) {}

So the problem is to pass the path variable to PreAuthorize annotation. Can SPeL help me in this situation?

You can use Expression-Based Access Control

@GetMapping("/{s}")
@PreAuthorize("@myMethod(#s, Constant.WRITE")
public ResponseEntity<MyDto> getDto(
    @PathVariable("s") String s
) {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM