com.airlenet.repo.domain.Result Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of play-repo Show documentation
Show all versions of play-repo Show documentation
The Repository of Play Framework.
The newest version!
package com.airlenet.repo.domain;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
public class Result {
private static Result init() {
return new Result();
}
public static Result success() {
return init().code(ResultCode.success).message(ResultCode.success.getMessage());
}
public static Result failure() {
return init().code(ResultCode.failure).message(ResultCode.failure.getMessage());
}
public static Result validateError() {
return init().code(ResultCode.validateError).message(ResultCode.validateError.getMessage());
}
public static Result accessDenide() {
return init().code(ResultCode.accessDenide).message(ResultCode.accessDenide.getMessage());
}
public static Result notLogin() {
return init().code(ResultCode.notLogin).message(ResultCode.notLogin.getMessage());
}
public static Result exception() {
return init().code(ResultCode.exception).message(ResultCode.exception.getMessage());
}
public static Result notFound() {
return init().code(ResultCode.notFound).message(ResultCode.notFound.getMessage());
}
public static Result unknown() {
return init().code(ResultCode.unknown).message(ResultCode.unknown.getMessage());
}
public static Result captchaError() {
return init().code(ResultCode.captchaError).message(ResultCode.captchaError.getMessage());
}
public static Result langError(String code,String defaultMsg,Object[] args) {
return init().code(ResultCode.lng.lang(code,args)).message(defaultMsg);
}
public static Result langError(String code,String defaultMsg) {
return init().code(ResultCode.lng.lang(code,null)).message(defaultMsg);
}
public static Result langError(String code) {
return init().code(ResultCode.lng.lang(code,null)).message(null);
}
private ResultCode code;
private String message;
private Map extraProperties = new HashMap<>();
private List errors = new ArrayList<>();
public ResultCode getCode() {
return code;
}
public Result code(ResultCode code) {
this.code = code;
return this;
}
public String getMessage() {
return message;
}
public Result message(String message) {
this.message = message;
return this;
}
public Map getExtraProperties() {
return extraProperties;
}
public List getErrors() {
return errors;
}
public Result addProperties(String key, Object value) {
this.extraProperties.put(key, value);
return this;
}
public Result setContent(Object value){
this.extraProperties.put("content",value);
return this;
}
public Result extraProperties(Map extraProperties) {
this.extraProperties = extraProperties;
return this;
}
public Result error(List errors) {
this.errors = errors;
return this;
}
public Result error(String objectName, String defaultMessage) {
this.errors.add(new ObjectError(objectName, defaultMessage));
return this;
}
public Result error(String objectName, String field, String defaultMessage) {
this.errors.add(new FieldError(objectName, field, defaultMessage));
return this;
}
public enum ResultCode {
success("操作成功"), failure("操作失败"), validateError("验证错误"), accessDenide("无权限访问"),notFound("404"), notLogin("未登录"), captchaError("验证码错误"), exception(
"系统异常"), unknown("未知情况"), lng("");
private final String message;
private String lang;
private Object[] args;
ResultCode(final String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public ResultCode lang(String lang,Object[] args){
this.lang = lang;
this.args = args;
return this;
}
public Object[] getArgs() {
return args;
}
public String getLang(){
return this.lang;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy