https://my.oschina.net/huangyong/blog/158380 推荐阅读
一般我们类都会继承BaseBean或者BaseEntity之类的类。那这个类能干什么??
假设BaseEntity有这样的方法
public abstract class BaseEntity implements Serializable {
/**
* 将当前对象转成json格式
* @return
*/
public String toJsonString(){
return JSON.toJSONString(this);
}
}
实体类继承此类
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserEntity extends BaseEntity {
private int id;
private String name;
private String gender;
}
Test测试
public static void main(String[] args) {
UserEntity userEntity = new UserEntity().builder().id(1).name("jack").gender("man").build();
System.out.println(userEntity.toString());
System.out.println(userEntity.toJsonString()); //调用base的方法
}
打印结果
UserEntity(id=1, name=jack, gender=man) {"gender":"man","id":1,"name":"jack"}
--------------------------------------------
除此之外,还能干什么