我写的这个成功返回的方法总是报错,希望老师帮助解决一下
@Getter
@Setter
public class CustomType {
protected boolean success;
protected Integer code;
protected String message;
@JsonInclude(value = JsonInclude.Include.NON_NULL)
protected Object data;
protected String request;
}
public class Custom extends CustomType{
@Resource
private ExceptionCodeConfiguration codeConfiguration;
public Custom (Integer code){
this.success = true;
this.code = code;
this.message = codeConfiguration.getMessage(code);
this.request = RequestUtil.getSimpleRequest();
}
@GetMapping("/text")
public Custom test() {
return new Custom(1);
}
运行时总是报错:Resolved [java.lang.NullPointerException],
不知如何更改,希望老师指点指点,谢谢了,🙏🙏
如果这样写是没有问题的:
@GetMapping("/text")
public Custom test() {
throw new NotFoundException(1);
}
返回:
相关代码:
{
"code": 1,
"message": "创建成功",
"request": "GET /cms/text/text"
}
36
收起
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星