标签:als 项目文件 mamicode 编写 boot code expired ima 文件
public enum DemoErrorEnum {
SUCCESS("操作成功", "0000"),
PARAM_NULL("参数为空", "1001"),
TOKEN_EXPIRED("token已过期", "2007"),
SERVER_ERROR("服务器异常,请稍后重试", "5001"),
;
private String code;
private String message;
public String getCode() {
return code;
}
public String getMessage() {
return message;
}
DemoErrorEnum(String message, String code) {
this.message = message;
this.code = code;
}
public static String getErrorMsg(String code) {
for (DemoErrorEnum e : DemoErrorEnum.values()) {
if (e.getCode().equals(code)) {
return e.message;
}
}
return null;
}
}
import com.naylor.interfacedesign.domain.demo.error.DemoErrorEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Accessors(chain = true)
public class ResultDTO<T> implements Serializable {
private boolean success;
private String resultMessage;
private String resultCode;
private T result;
public static ResultDTO error(DemoErrorEnum errorEnum) {
return new ResultDTO().setSuccess(false).setResultMessage(errorEnum.getMessage()).setResultCode(errorEnum.getCode());
}
public static ResultDTO success(DemoErrorEnum errorEnum) {
return new ResultDTO().setSuccess(true).setResultCode(errorEnum.getCode());
}
public static ResultDTO success() {
return new ResultDTO().setSuccess(true).setResultCode(DemoErrorEnum.SUCCESS.getCode()).setResultMessage(DemoErrorEnum.SUCCESS.getMessage());
}
}
import com.naylor.interfacedesign.domain.demo.controller.param.GetUserParam;
import com.naylor.interfacedesign.domain.demo.dto.ResultDTO;
import com.naylor.interfacedesign.domain.demo.dto.UserDTO;
import com.naylor.interfacedesign.domain.demo.error.DemoErrorEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/demo")
@Slf4j
public class DemoController {
@GetMapping("/user")
public ResultDTO<UserDTO> getUser(GetUserParam param) {
if (null == param) {
return ResultDTO.error(DemoErrorEnum.PARAM_NULL);
}
UserDTO userDTO = null;
// do something
return null != userDTO ? ResultDTO.success().setResult(userDTO) : ResultDTO.error(DemoErrorEnum.SERVER_ERROR);
}
}
标签:als 项目文件 mamicode 编写 boot code expired ima 文件
原文地址:https://www.cnblogs.com/Naylor/p/13330127.html