定义统一的返回格式(controller)

一:单独创建一个类来表示返回结果

package com.jk51.commons.dto;

/**
 * Created by Administrator on 2017/6/13.
 */
public class PacketHead {

    public static final String STATUS_SUCCESS = "OK";//成功
    public static final String STATUS_ERROR = "ERROR";//成功

    private String status; //返回状态
    private String msg;    //返回信息

    public PacketHead() {
        status = STATUS_SUCCESS;
    }
    public PacketHead(String status, String result) {
        this.status = status;
        this.msg = msg;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}

  

二:创建返回类ResultData 以后controller可以统一采用此类作为返回结果

/**
 * 返回结果封装
 * Created by Administrator on 2018/7/3.
 */
public class ResultData extends PacketHead{

    private Object data;

    public ResultData(){
        this.setStatus(STATUS_SUCCESS);
    }

    public Object getData() {
        return data;
    }

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

}

  

用法如图实例

 

posted @ 2018-07-03 12:00  不二尘  阅读(498)  评论(0编辑  收藏  举报