【发布时间】:2019-02-22 22:48:30
【问题描述】:
我创建了添加到我的 Java 类字段的自定义注释。 当我创建该类的对象时,我希望我的自定义注释字段具有值:null 或“”或“customAnnotation” 例如:
@Entity
public class User implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "address_id")
private Long id;
@MyCustomAnnotation
private String firstname;
private String lastname;
....
当我在项目的某处创建对象时:
User user = new User();
user.setFirstname("John");
user.setLastname("Smith");
我希望它是:
String firstname = user.getFirstname() // firstname is "" or null
String lastname = user.getLastname() // lastname is "Smith"
如何创建方法来查找项目中所有类中的所有注释字段并对所有类执行相同操作?这个方法存放在哪里? 我正在开发 Maven,Spring Boot 项目。
【问题讨论】:
标签: java maven spring-boot annotations aop