Java spring引导,POJO中的Lombok用于响应实体体
我为API的默认错误响应体创建了一个对象。 因此,我创建了我的类,声明了构造函数和参数,并从lombok添加了Java spring引导,POJO中的Lombok用于响应实体体,java,spring-boot,lombok,Java,Spring Boot,Lombok,我为API的默认错误响应体创建了一个对象。 因此,我创建了我的类,声明了构造函数和参数,并从lombok添加了@Getter和@Setter @Getter @Setter public class ResponseError { private Date timestamp; private int status; private int code; private String message; public ResponseError(Da
@Getter
和@Setter
@Getter
@Setter
public class ResponseError {
private Date timestamp;
private int status;
private int code;
private String message;
public ResponseError(Date timestamp, int status, int code, String message) {
this.timestamp = timestamp;
this.status = status;
this.code = code;
this.message = message;
}
}
当我在ResponseEntity的body response中启动对象时,我在构建时遇到以下错误:
No converter found for return value of type: class com.example.api.controller.response.ResponseError
如果我在我的类中手动创建getter和setter,它就会工作。
我以为龙目巨人会为我做这件事,是吗?
@Getter
/@Setter
应该应用于字段。这应该是你的代码
公共类响应错误{
@吸气剂
@塞特
私有日期时间戳;
@吸气剂
@塞特
私人身份;
@吸气剂
@塞特
私有整数码;
@吸气剂
@塞特
私有字符串消息;
}
对于类级别的事件更好的解决方案是使用@Data
注释
它为所有字段生成getter,这是一个有用的.toString
方法,以及检查所有非瞬态字段的.hashCode
和.equals
实现。
它还将为所有非最终字段以及构造函数生成setter。
它相当于拥有所有注释:@Getter
@Setter
@RequiredArgsConstructor
@ToString
@EqualsAndHashCode
如果您希望使用@Data
,您的代码将是
@数据
公共类响应者{
私有日期时间戳;
私人身份;
私有整数码;
私有字符串消息;
}
- 更新/安装Idea的Lombok插件
- Idea的注释过程
- 为插件启用注释过程