如何实现自定义类字段的注释并实施保存服务方法以清理类的字段
我有三个类,
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;
}
我想要在服务层上更多的抽象,因此设计了baseService
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);
}
我想设计注释@clearfiled
,在实体的字段上标记,这样的
public class A {
@ClearFiled
private int id;
private String name;
@ClearFiled
private int validate;
}
效果是替换以下代码
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);
}
}
。我要这样做吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论