I have three Class

public class A {
  private int id;
  private String name;
  private int validate;
}

public class B {
  private int id;
  private LocalDateTime modifiyTime;
}

public class C {
  private int id;
  private int sequence;
}

I want more abstract at the Service layer, so BaseService was designed

public interface BaseService<T> {
  default void saveCheck(T t) {
      clear(t);
      duplicateCheck(t);
      preProcess(t);
      if(save(t)) {
        postProcess(t);
      }
  }
  
  void duplicateCheck(T t);
  
  void clear(T t);

  void preProcess(T t);

  boolean save(T t);

  void postProcess(T t);
}

I want to design an annotation @ClearFiled, marked on the entity's field, like this

public class A {
  @ClearFiled
  private int id;
  private String name;
  @ClearFiled
  private int validate;
}

Its effect is to replace the following code

public interface IAService extends BaseService<A> {

}

public class AServiceImpl extends IAService {
  // @ClearFiled is used to omit this part of the code
  // this method belong to BaseService
  @Override
  public void clear(A a) {
    a.setId(0);
    a.setValidate(0);
  }
}

How do i do this?

0

There are 0 best solutions below