我有Spring Rest控制器,如下所示:
@RestController
@RequestMapping(value = "/v1/files")
public class DataReader {
@GetMapping(value = "/",produces = MediaType.TEXT_HTML_VALUE)
public Employee readData () {
Employee employee = new Employee();
employee.setName("GG");
employee.setaddress("address");
employee.setPostCode("postal code");
return employee;
}
}
基本上,我希望此控制器返回html内容。但是,当我从浏览器或邮递员访问URI时,出现以下异常:
There was an unexpected error (type=Not acceptable,status=406).
Could not find acceptable representation
org.springframework.web.HttpMediaTypeNotacceptableException: Could not find acceptable representation
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:316)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:181)