我有下面的函数,我试图用我的对象列表返回 ResponseEntity。我不知道我错过了什么。
@RequestMapping(method = RequestMethod.GET, path = "/test")
public ResponseEntity<List<Book>> test(@RequestParam("param1") String param1) {
return new ResponseEntity<List<Book>>(this.service.searchOnParam1(param1), HttpStatus.OK);
}
我收到以下错误。我该如何克服呢?
WARN 37968 --- [nio-8080-exec-1] .wsmsDefaultHandlerExceptionResolver:已解决 [org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示]
书类。
public class Book implements Serializable, Message
{
Logger log = LogManager.getLogger(this.getClass());
private long id;
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
@MsgField(id = "COUNT")
@JsonProperty("COUNT")
private String itemCount;
@MsgField(id = "name")
@JsonProperty("name")
private String name;
@MsgField(id = "author")
@JsonProperty("author")
private String author;
@MsgField(id = "price")
@JsonProperty("price")
private String price;
public String getPriceFormatted(Locale locale){
String returnValue = "0";
try {
final NumberFormat formatter = NumberFormat.getInstance(locale);
formatter.setMaximumFractionDigits((int) 2);
formatter.setMinimumFractionDigits((int) 2);
formatter.setMinimumIntegerDigits(1);
formatter.setRoundingMode(RoundingMode.HALF_DOWN);
returnValue = formatter.format(price);
} catch (NumberFormatException ex) {
log.catching(ex);
}
return returnValue;
}
}