对于model层,如果返回的结果集不确定,有可能是一个对象,也有可能是一个Boolean这种类型,那么可以将model写成R的形式
public class ResultDTO<R> implements Serializable{
/**
*
*/
private static final long serialVersionUID = -8276209086617803215L;
private Boolean isSuccess;
private R DTO;
private String desc;
private Integer returnCode;
private Paginator paginator;
public ResultDTO(){
this.isSuccess = Boolean.FALSE;
this.paginator = new Paginator();
}
public Boolean getIsSuccess() {
return isSuccess;
}
public void setIsSuccess(Boolean isSuccess) {
this.isSuccess = isSuccess;
}
public R getDTO() {
return DTO;
}
public void setDTO(R dTO) {
DTO = dTO;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Integer getReturnCode() {
return returnCode;
}
public void setReturnCode(Integer returnCode) {
this.returnCode = returnCode;
}
public Paginator getPaginator() {
return paginator;
}
public void setPaginator(Paginator paginator) {
this.paginator = paginator;
}
public static <T> ResultDTO<T> buildErrorResultDTO(ResultDTO<T> resultDTO, String msg) {
resultDTO.setIsSuccess(false);
resultDTO.setDTO(null);
resultDTO.setDesc(msg);
return resultDTO;
}
}
调用的时候使用如下方式调用:
ResultDTO<Boolean> resultDTO = new ResultDTO<Boolean>();
上面的形式就说明DTO的形式为R这里也就是Boolean
另外,如果对于返回两个参数都不确定,那么也可以采用相似的方式
public class TwoTuple<A, B> {
private A a;
private B b;
public TwoTuple(){
super();
}
public TwoTuple(A a, B b){
this.a = a;
this.b = b;
}
public A getA() {
return a;
}
public void setA(A a) {
this.a = a;
}
public B getB() {
return b;
}
public void setB(B b) {
this.b = b;
}
@Override
public String toString() {
return "TwoTuple [a=" + a + ", b=" + b + "]";
}
}
使用方式:
TwoTuple<Integer, List<String>> tuple = new TwoTuple<Integer, List<String>>();
List<String> idResultList = new ArrayList<String>();
tuple.setA(0);
tuple.setB(idResultList);
@NoneResultDecrator
这个RPC的注解,如果加上,那么就只返回自己定义的resultModel类型格式,如果加上,就会经过RPC渲染
不加的:
加的: