用相同注释建立一个方面可以在班级或方法上,并且可以是
我正在创建一个自定义的度量方面,因此我不必在代码中执行公制(“保存”,“订单”)。我的组织使用自定义公制库。
因此,我想创建一个自定义指标注释和方面,为我做到这一点。
我希望能够将注释@postgressmetric添加到类和方法中。它看起来像这样:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface PostgressMetric {
String value() default "";
String table() default "";
}
如果指标在同类中,那么我想将这些值用作“默认值”。因此,您可以拥有这样的东西:
@Repository
@PostgressMetric(table = "order")
public class OrderRepository {
@PostgressMetric("save")
public void save(Order order) {
}
}
这也是一个有效的设置:
@Repository
public class OrderRepository {
@PostgressMetric(table="order", value="save")
public void save(Order order) {
}
}
当然,这也是一个有效的设置:
@Repository
@PostgressMetric(table="order", value="save")
public class OrderRepository {
public void save(Order order) {
}
}
现在,在我的方面,我想从类中获取注释,然后从方法中获取注释。如果类具有注释,则获取表格和价值并将其用作默认值。如果该方法具有注释,则如果值不为空白,请使用它们覆盖类注释中指定的默认值。
是否有一种标准的方式来获取两个注释,还是只是蛮力获得班级值,然后获得方法值并覆盖它们?
I'm creating a custom Metric Aspect so that I don't have to do METRIC.aboutTo("save", "order") in the code. My organization uses custom metric libraries.
So, I want to create a custom metric annotation and aspect to do this for me.
I'm looking to be able to add the annotation @PostgressMetric to both the class and the method. It would look something like this:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface PostgressMetric {
String value() default "";
String table() default "";
}
If the metric is on the class, then I want to use those values as "defaults". So you could have something like this:
@Repository
@PostgressMetric(table = "order")
public class OrderRepository {
@PostgressMetric("save")
public void save(Order order) {
}
}
This is also a valid setup:
@Repository
public class OrderRepository {
@PostgressMetric(table="order", value="save")
public void save(Order order) {
}
}
and of course this is also a valid setup:
@Repository
@PostgressMetric(table="order", value="save")
public class OrderRepository {
public void save(Order order) {
}
}
Now, in my aspect I want to get the annotation from the class, then get the annotation from the method. If the class has the annotation then get the table and value and use those as default values. If the method has the annotation then if the values aren't blank, use them to override the default values specified in the class annotation.
Is there a standard way to get the two annotations, or is it just a brute force get the class values and then get the method values and override them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论