当前位置: 首页 > 知识库问答 >
问题:

RestController类中的Spring Boot中不支持内容类型“text/plain;charset=UTF-8”错误

高弘光
2023-03-14

我在Spring Boot应用程序中获得了以下@RestController:

@Data
@RestController
public class Hello {

    @Autowired
    private ResturantExpensesRepo repo;

    @RequestMapping(value = "/expenses/restaurants",method = RequestMethod.POST,consumes =MediaType.APPLICATION_JSON_VALUE ,
            headers = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public void hello(@RequestBody ResturantExpenseDto dto)
    {
        Logger logger = LoggerFactory.getLogger("a");
        logger.info("got a request");

        ResturantExpenseEntity resturantExpenseEntity = new ResturantExpenseEntity();
        resturantExpenseEntity.setDate(new Date(System.currentTimeMillis()));
        resturantExpenseEntity.setName(dto.getName());
        resturantExpenseEntity.setExpense(dto.getExpense());
        repo.save(resturantExpenseEntity);
    }
}

当我尝试从RestClient/RestedClient(这两个是mozila的插件)发送请求时,我得到以下错误:

{“时间戳”:1512129442019,“状态”:415,“错误”:“不支持的媒体类型”,“消息”:“内容类型'text/plain;charset=utf-8'不支持”,“路径”:“/exposities/restaurants”}

这个错误声明endpoint不支持Json内容,但我确实把

消耗=mediatype.application_json_value

我错过了什么?

共有1个答案

爱海
2023-03-14

响应较晚,但我也遇到了同样的问题,张贴答案可能对某些人有用,所以我安装了Postman,然后只需将内容类型更改为Application/JSON

 类似资料: