@Data
@Builder
public class ResultWapper<T> implements Serializable {
private int code;
private String msg;
private T data;
//返回成功的包装
public static ResultWapper.ResultWapperBuilder getSuccessBuilder(){
return ResultWapper.builder().code(StateCodeEnum.SUCCESS.getCode()).msg(StateCodeEnum.SUCCESS.getMsg());
}
//返回错误包装
public static ResultWapper.ResultWapperBuilder getFailBuilder(){
return ResultWapper.builder().code(StateCodeEnum.FAIL.getCode()).msg(StateCodeEnum.FAIL.getMsg());
}
}
具体调用:
@PostMapping("/reg")
public ResultWapper register(@RequestBody @Valid UserMemberDTO userMemberDTO){
String result = umsMemberService.register(userMemberDTO);
return ResultWapper.getSuccessBuilder().data(result).build();
}