首页 > 代码库 > web接入层 传入参数的格式化及web返回值传出数据的参数格式化,都要统一
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 = http://www.mamicode.com/""; private int result = 200; // TODO 分页对象 public ResultObject(String res_info) { this.res_info = res_info; } public ResultObject(Object data) { this.data =http://www.mamicode.com/ 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 =http://www.mamicode.com/ 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 = http://www.mamicode.com/""; private int result = 200; // TODO 分页对象 public ResultObject(String res_info) { this.res_info = res_info; } public ResultObject(Object data) { this.data =http://www.mamicode.com/ 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返回值传出数据的参数格式化,都要统一
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。