码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-12-14 21:25:46      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:入参   div   his   序列化   name   src   object   格式化   final   

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;
    }

 

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

标签:入参   div   his   序列化   name   src   object   格式化   final   

原文地址:http://www.cnblogs.com/panxuejun/p/6180706.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!