使用Java 8出现注释时添加另一个注释
我目前正在创建自己的CRUD管理课程。为此,我处理的是这样的注释:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface DTO {
String table() default "";
}
带有此注释注释的每个对象还需要从LOMBOK中使用“ Noargsconstructor” - 宣布,只能应用于类或枚举类型。因此,我不能仅仅将其添加到DTO定义的注释之上。我该如何实现,每个具有DTO通道的班级也可以接收Noargsconstructor,而无需每次手动添加它?
这很好:
@Data
@NoArgsConstructor
@DTO(table = "cast2")
public class CastDTO {
@Column
private Integer mid;
@Column
private Integer pid;
@Column
private String role;
}
但是我宁愿每次创建另一个类时都不必添加noargsconstructor
。
I am currently creating my own CRUD-managing class. For this purpose I work with an annotation that looks like this:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface DTO {
String table() default "";
}
Every object annotated with this annotation also needs to have the "NoArgsConstructor"-Annotation from lombok, which can only be applied to class or enum types. Therefore I cannot just add it on top of the annotations of the definition of DTO. How can I achieve, that every class that has the DTO-Annotation also receives the NoArgsConstructor without it being required to add it every time manually?
This works fine:
@Data
@NoArgsConstructor
@DTO(table = "cast2")
public class CastDTO {
@Column
private Integer mid;
@Column
private Integer pid;
@Column
private String role;
}
but I'd rather not have to add NoArgsConstructor
every time I create another Class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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