自定义注释-Spring Boot

时间:2018-07-13 14:49:08

标签: java spring spring-boot annotations aop

我对Spring Boot中的 @Annotation 有疑问。我需要创建一个自定义注释,它将检查各种规则并返回TRUE或FALSE。

我的自定义注释:

@MyAnnotationExample(value="idOfMyRequestHere")

在注释中,我需要通过路径 {id} ,这可能吗?

然后,如果可能的话,在我的注释中,我将使用此路径{id}验证某些规则,在验证此规则后,返回值为TRUE或FALSE。

如果返回值为TRUE,将返回我的CARS,如果返回FALSE,则将向用户返回错误。

我的控制器:

@RequestMapping(value = "/test/{id}", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
@ResponseStatus(HttpStatus.OK)
@MyAnnotationExample(value="idOfMyRequestHere")
public Car getTest(@PathVariable("id") Integer id) {

    List<Car> cars = new ArrayList<Car>();

    cars = this.carService.getCars(id);

    return cars;
}

0 个答案:

没有答案
相关问题