本文主要是介绍JavaWeb_响应_@ResponseBody统一响应结果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、@ReponseBody
二、统一响应结果
示例代码:
public class Result {private Integer code;//1 成功 , 0 失败private String msg;//提示信息private Object data;//数据 datapublic Result() {}public Result(Integer code, String msg, Object data) {this.code = code;this.msg = msg;this.data = data;}public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}public Object getData() {return data;}public void setData(Object data) {this.data = data;}public static Result success(Object data){return new Result(1,"success",data);}public static Result success(){return new Result(1,"success",null);}public static Result error(String msg){return new Result(0,"msg",null);}@Overridepublic String toString() {return "Result{" +"code=" + code +", msg='" + msg + '\'' +", data=" + data +'}';}
}
这篇关于JavaWeb_响应_@ResponseBody统一响应结果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!