错误: org.springframework.web.HttpMediaTypeNotSupportedException: Content type ‘text/plain;charset=UTF-8’ not supported(见图一)
解决方法:需要在postman里面将Headers中设置Content-type为application/json(见图二)
**:
- application/json 作为响应头比较常见。实际上,现在越来越多的人把它作为请求头,用来告诉服务端消息主体是序列化后的 JSON 字符串,其中一个好处就是JSON 格式支持比键值对复杂得多的结构化数据。
- 后端代码用可序列化的对象接收的
@ApiOperation(value = "给食材类赋值",tags = "食材类")
@PostMapping(value = "get-String")
public String getString(@RequestBody IngredientsVO ingredientsVO){
IngredientsVO vo = new IngredientsVO();
vo.setCode(ingredientsVO.getCode());
vo.setName(ingredientsVO.getName());
return JSONObject.toJSON(vo).toString();
}