Result类

发布于 2018-12-11  165 次阅读


import java.util.HashMap;
import java.util.Map;

import org.springframework.util.StringUtils;

public class Result {
// code 状态码,成功:000000 失败:999999
private String code;
// 错误信息
private String message;
// 返回数据(链式)
private Map data = new HashMap<>();

// 成功
public static Result success() {
Result result = new Result();
result.setCode("000000");
result.setMessage("操作成功");
return result;
}

// 失败
public static Result error(String str) {
Result result = new Result();
result.setCode("999999");
if (StringUtils.isEmpty(str)) {
result.setMessage("操作失败");
} else {
result.setMessage(str);
}
return result;
}

// 添加
public Result add(String key, Object value) {
this.getData().put(key, value);
return this;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public Map getData() {
return data;
}

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

}

传值 int类型
@PathVariable("currPage") int currPage

传值 字符串
@RequestParam(value = "search", required = false)

事务注解
@Transactional(propagation = Propagation.REQUIRED, rollbackForClassName = "Exception")

事务配置 spring-mybatis


再无夏秋