2012-01-27 16 views
2

私は問題があり、誰かが私を助けてくれることを願っています。Spring - AOP - 注釈コードの生成

私は、ドメインエンティティ持っている

私はSpringフレームワークを使用して、私は自分のドメインクラスの1内部メソッドを生成したい...:

@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 "メソッドをこのドメインに追加します。 方法は、このような「CustomAnnotation」注釈ましfileds、含まれています。私は解決策を見つけることができる場所

@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 
    } 
} 

私は春とAOPに非常に新しいです、誰も私を助けることができますか?

おかげ

答えて

0

あなたは、あなたがInter-Type-Declarationと呼ばれるものを(あなたは完全な例は、春のカンガループロジェクトを作成したいので、もしこの技術が重く、春Rooのに使用されている)を行うことができますコンパイル時にAspectJを必要としています。

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 
    } 

} 
関連する問題