我遇到了问题,希望有人可以帮助我。
我使用Spring框架,我希望在我的一个域类中生成一个方法...
我有一个Domain实体:
@Entity
class AbcDomain {
private int id;
@CustomAnnotation(p1="x1", p2="y1")
private String a;
@CustomAnnotation(p1="x2", p2="y2")
private String b;
@CustomAnnotation(p1="3", p2="y3")
private int c;
private Set<Integer> d;
... getters and setters
}
我希望为这个域生成一个“m”方法。 这些方法包含fileds,它有这样的“CustomAnnotation”注释:
@Entity
class AbcDomain {
... Prev code ...
public String m() {
if ( "x1".equals(a) ) // "x1" comes from the annotation's p1 param
return "y1"; // "y1" comes from the annotation's p2 param
if ( "x2".equals(b) ) // "x2" comes from the annotation's p1 param
return "y2"; // "y2" comes from the annotation's p2 param
if ( c == 3 ) // 3 comes from the annotation's p1 param
return "y3"; // "y3" comes from the annotation's p1 param
}
}
我是春天和新手的新人,有人可以帮助我在哪里可以找到解决方案吗?
由于
答案 0 :(得分:0)
你需要编译时间AspectJ然后你可以做一些叫做Inter-Type-Declaration的事情(这个技术在Spring Roo中大量使用,所以如果你想要一个完整的例子来创建一个spring roo项目)。
privileged aspect AbcDomain_Extension {
public String m() {
if ( "x1".equals(a) ) // "x1" comes from the annotation's p1 param
return "y1"; // "y1" comes from the annotation's p2 param
if ( "x2".equals(b) ) // "x2" comes from the annotation's p1 param
return "y2"; // "y2" comes from the annotation's p2 param
if ( c == 3 ) // 3 comes from the annotation's p1 param
return "y3"; // "y3" comes from the annotation's p1 param
}
}