一. 实体类简述
实体类其实就是俗称的POJO,这种类一般不实现特殊框架下的接口,在程序中仅作为数据容器用来持久化存储数据用的
public class A{ private String id; public String getId(){ return this.id; } public void setId(String id){ this.id = id; } }
其实这样写的意义就在于封装,id作为类A的成员变量,也称属性,一般情况下拥有读和写的能力,我们将id设为private,则外部无法对其直接进行操作,同时通过set方法提供了外部更改其value的方法,又通过get方法使外界能读取该成员变量的值。(必须有set,get方法)
public class Category { private Integer id; @JSONField(name="nameCN") private String cateNameCN; @JSONField(name="nameEN") private String cateNameEN; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getCateNameCN() { return cateNameCN; } public void setCateNameCN(String cateNameCN) { this.cateNameCN = cateNameCN; } public String getCateNameEN() { return cateNameEN; } public void setCateNameEN(String cateNameEN) { this.cateNameEN = cateNameEN; } public Category() { super(); } public Category(Integer id, String cateNameCN, String cateNameEN) { super(); this.id = id; this.cateNameCN = cateNameCN; this.cateNameEN = cateNameEN; } public static Category fromResultSet(ResultSet rs) throws SQLException { return new Category(rs.getInt("Id"), rs.getString("cateNameCN"), rs.getString("cateNameEN")); }
2.request和response中用于接收参数的entity
public class PlatformRequestHeader { @JSONField(name = "uid") private String userId; @JSONField(name = "clid") private String clientId; @JSONField(name = "cid") private Integer companyId; @JSONField(name = "uip") private String userIp; @JSONField(name = "rid") private String requestId; public PlatformRequestHeader() { this.userId = ""; this.clientId = ""; this.companyId = -1; this.userIp = ""; this.requestId = ""; } public PlatformRequestHeader(String userId, String clientId, Integer companyId, String userIp, String requestId) { this.userId = userId; this.clientId = clientId; this.companyId = companyId; this.userIp = userIp; this.requestId = requestId; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getClientId() { return clientId; } public void setClientId(String clientId) { this.clientId = clientId; } public Integer getCompanyId() { return companyId; } public void setCompanyId(Integer companyId) { this.companyId = companyId; } public String getUserIp() { return userIp; } public void setUserIp(String userIp) { this.userIp = userIp; } public String getRequestId() { return requestId; } public void setRequestId(String requestId) { this.requestId = requestId; } @Override public String toString() { return "{\"uid\":\"" + userId + "\",\"clid\":\"" + clientId + "\",\"cid\":" + companyId + ",\"uip\":\"" + userIp + "\",\"rid\":\"" + requestId + "\"}"; } }
public class ResponseModel implements Serializable { /** * */ private static final long serialVersionUID = 1L; @JSONField(name = "ers") private List<ErrorInfo> errors; @JSONField(name = "err") private ErrorInfo errorInfo; @JSONField(name = "data") private Object data; public ErrorInfo getErrorInfo() { return errorInfo; } public void setErrorInfo(ErrorInfo errorInfo) { this.errorInfo = errorInfo; } public Object getData() { return data; } public void setData(Object data) { this.data = data; } public List<ErrorInfo> getErrors() { return errors; } public void setErrors(List<ErrorInfo> errors) { this.errors = errors; } public ResponseModel() { } public ResponseModel(List<ErrorInfo> errors, Object object) { this.errors = errors; this.data = object; } public ResponseModel(ErrorInfo error, Object object) { this.errorInfo=error; this.data = object; }
3.logic里面的工具entity-----类似于map(不过里面只有一组值)
public class Tuple implements Serializable { private static final long serialVersionUID = -8719929625763890308L; public static <A, B> Tuple2<A, B> tuple(A item1, B item2) { return new Tuple2<A, B>(item1, item2); } public static <A, B, C> Tuple3<A, B, C> tuple(A item1, B item2, C item3) { return new Tuple3<A, B, C>(item1, item2, item3); } public static final class Tuple2<A, B> extends Tuple implements Serializable { /** * gen by eclipse */ private static final long serialVersionUID = 7263645006696591635L; private A item1; private B item2; public Tuple2() { } public Tuple2(A item1, B item2) { this.item1 = item1; this.item2 = item2; } public A getItem1() { return item1; } public void setItem1(A item1) { this.item1 = item1; } public B getItem2() { return item2; } public void setItem2(B item2) { this.item2 = item2; } } public static final class Tuple3<A, B, C> extends Tuple implements Serializable { /** * gen by eclipse */ private static final long serialVersionUID = 482545776907024160L; private A item1; private B item2; private C item3; public Tuple3(A item1, B item2, C item3) { this.item1 = item1; this.item2 = item2; this.item3 = item3; } public A getItem1() { return item1; } public void setItem1(A item1) { this.item1 = item1; } public B getItem2() { return item2; } public void setItem2(B item2) { this.item2 = item2; } public C getItem3() { return item3; } public void setItem3(C item3) { this.item3 = item3; } } public static final class Tuple4<A, B, C, D> extends Tuple implements Serializable { /** * gen by eclipse */ private static final long serialVersionUID = 482545776907024160L; private A item1; private B item2; private C item3; private D item4; public Tuple4(A item1, B item2, C item3, D item4) { this.item1 = item1; this.item2 = item2; this.item3 = item3; this.item4 = item4; } public A getItem1() { return item1; } public void setItem1(A item1) { this.item1 = item1; } public B getItem2() { return item2; } public void setItem2(B item2) { this.item2 = item2; } public C getItem3() { return item3; } public void setItem3(C item3) { this.item3 = item3; } public D getItem4() { return item4; } public void setItem4(D item4) { this.item4 = item4; } } }
备注:实体类就是有set和get方法的简单JAVA对象,定义的时候一定要记住要序列化哦!!!