我想在 Spring Boot 中实现一个注释。需要获取路径变量并在注释中使用。
@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)
}
我在PreAuthorize中得到这样的参数:#id。但是在这个函数中,变量路径的名字作为一个字符串来函数。
哪里做错了?我该如何解决这个问题?