问题
I want implement an annotation in spring boot. It's required to get path variable and use in annotation.
@PostMapping("/v1/{id}")
@HasZone(id = "#id")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun createCompany( @PathVariable id: String) {
....
}
@Target(AnnotationTarget.FUNCTION)
annotation class HasZone(vararg val id: String)
@Before("@annotation(hasZone)")
fun checkZonePermissions(hasZone: HasZone) {
println(hasZone.id)
}
I get the parameter in PreAuthorize like this: #id. But in this function, name of the variable path to function as a string.
Where is the wrong thing to do? How can I fixed the problem?
来源:https://stackoverflow.com/questions/60297081/get-pathvariable-in-aspect-spring-boot