controller 반환값 봉인

1433 단어
public class Result {
	private int code;
	private String msg;
	private T data;

	/**
	 *  
	 * */
	public static  Result success(T data){
		return new  Result(data);
	}
	
	/**
	 *  
	 * */
	public static  Result error(CodeMsg cm){
		return new  Result(cm);
	}
	
	private Result(T data) {
		this.code = 0;
		this.msg = "success";
		this.data = data;
	}
	
	private Result(CodeMsg cm) {
		if(cm == null) {
			return;
		}
		this.code = cm.getCode();
		this.msg = cm.getMsg();
	}

	public int getCode() {
		return code;
	}
	public String getMsg() {
		return msg;
	}
	public T getData() {
		return data;
	}
}

public class CodeMsg {
	private int code;
	private String msg;
	
	public static CodeMsg SUCCESS = new CodeMsg(0, "success");
	public static CodeMsg SERVER_ERROR = new CodeMsg(500100, " ");

	
	
	private CodeMsg(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	
	public int getCode() {
		return code;
	}
	public String getMsg() {
		return msg;
	}
}
// 
@RequestMapping("/success1")
    @ResponseBody
    public Result success1(){
        return Result.success(" ");
    }
    @RequestMapping("/error1")
    @ResponseBody
    public Result error1(){
        return Result.error(CodeMsg.SERVER_ERROR);
    }

좋은 웹페이지 즐겨찾기