foreword
In the past few days, I took advantage of the holiday to develop a project independently, taking advantage of this to integrate the learned technology and enrich my project experience. It will be open-sourced in the future, and everyone is welcome to support and star~
text
error occurs
After the project is running, open the interface document for testing and find that the response is wrong
Return to the console and view the log output:
Project error message:
Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]
Analyze and solve problems
The reason for the error is that the package class returned by the response lacks getXxx() and setXxx() methods
We can use lombok to simplify development and avoid handwriting getter and setter methods
1. Import lombok dependencies
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
2. Use the annotations provided by lombok to simplify development
@Builder
@Getter
@Setter
public class ResultVO<T> {
private Integer code;
private String msg;
@Nullable
private T data;
//...
}
Or use @Data directly
@Data
public class ResultVO<T>{
private Integer code;
private String msg;
private T data
//...
}
After this test again there is no problem.