2016-04-02 25 views
1

Ek Açıklama:geçişli sonucu

@Target(ElementType.METHOD) 
@Retention(RetentionPolicy.RUNTIME) 
public @interface Multipart { 

    Class acceptClass(); 

} 

Açıklamalı yöntemi:

@Multipart (acceptClass = SomeClass.class) 
public void someMethod(SomeClass a){ 
    //do stuff.. 
} 

MultipartAspect:

@Aspect 
public class MultipartAspect { 

    @Autowired(required=true) 
    private HttpServletRequest request; 

    @Pointcut(value = "@annotation(Multipart)", argNames = "multipart") 
    public void before(JoinPoint jp, Multipart multipart) {} 

    @Before("before()") 
    public SomeClass doStuffBeforeThing() { 
     SomeClass sc = new SomeClass(); //object of passed class 
     //do something.. 
     return sc;      //return this to annotated method(somemethod) 
    } 

} 

Ben metod çalışmaları ek açıklama yürütmek önce, bir nesne oluşturmak istiyorum sınıf (SomeClass) ve bu sınıfın geçiş nesnesini açıklamalı yönteme geçirdi. Bunu yapabilir miyim?

cevap

0

@Bunu yerine @Around önerisini kullanmalısınız.