web接入层 传入参数的格式化及web返回值传出数据的参数格式化,都要统一

1.web接入层 传入参数的格式化及web返回值传出数据的参数格式化,都要统一。

比如acSpace中,

传入层参数@RequestBody javaBean对象。统一转换为javabean传入参数。

返回值,统一返回ResultObject对象,resultObject实现了序列化。且resultObject中定义好了传输回去哪些属性,

3.ResultObject,定义的公共传出参数属性

public class ResultObject implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = -2523760680706423997L;
    private String res_info = "";
    private Object data = "";
    private int result = 200;

    // TODO 分页对象

    public ResultObject(String res_info) {
        this.res_info = res_info;
    }

    public ResultObject(Object data) {
        this.data = data;
    }

    public ResultObject(ResultCode ResultCode) {
        this.res_info = ResultCode.getName();
        this.result = ResultCode.getIndex();
    }

    @SuppressWarnings("unchecked")
    public <T extends ResultObject> T configErrMsg(ResultCode err) {
        this.setResult(err.getIndex());
        this.setRes_info(err.getName());
        return (T) this;
    }

    public ResultObject() {
    }

    public String getRes_info() {
        return res_info;
    }

    public void setRes_info(String res_info) {
        this.res_info = res_info;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

}

3.返回ResultObject对象中,定义了多个构造函数。

用于传入不同的类型,并将之返回。有

ResultObject(String res_info)
ResultObject(ResultCode ResultCode)
ResultObject(Object data)


    private static final long serialVersionUID = -2523760680706423997L;
    private String res_info = "";
    private Object data = "";
    private int result = 200;

    // TODO 分页对象

    public ResultObject(String res_info) {
        this.res_info = res_info;
    }

    public ResultObject(Object data) {
        this.data = data;
    }

    public ResultObject(ResultCode ResultCode) {
        this.res_info = ResultCode.getName();
        this.result = ResultCode.getIndex();
    }

    @SuppressWarnings("unchecked")
    public <T extends ResultObject> T configErrMsg(ResultCode err) {
        this.setResult(err.getIndex());
        this.setRes_info(err.getName());
        return (T) this;
    }
时间: 12-14