SpringBoot找不到可接受的表示

错误

1
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

原因

1
2
3
4
5
6
7
8
9
@RestController
public class ExchangeApiController {

// 返回的是json的对象
@RequestMapping(value = "/exchange", method = RequestMethod.POST)
public ApiResult exchange(@RequestAttribute("tradingReq") TradingReqDTO tradingReqDTO) {
return normalExchangeService.exchange(tradingReqDTO);
}
}
1
2
3
4
5
// 拦截器将response返回类型设置为了xml文件
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.setContentType("application/xml;charset=UTF-8");
}

最终导致,想要返回的是xml形式,结果返回了json格式,导致出现如上错误提示

赏个🍗吧
0%