【问题标题】:Getting 415 Unsupported Media Type in spring boot在 Spring Boot 中获取 415 Unsupported Media Type
【发布时间】:2020-01-12 12:33:00
【问题描述】:

控制器中的方法

    @RequestMapping(value = "/reactEmployee", method = RequestMethod.POST, consumes = "application/json")
    public String addEmployeereact(@RequestBody EmployeeEntity employeeEntity)
    {
        employeeManager.addEmployee(employeeEntity);
        return "redirect:/";
    }

来自 Postman 的 JSON 输入 Json input and 415 error in Postman

【问题讨论】:

  • 您为 Postman 中的标题 content-type 提供什么值?编辑:另外,EmployeeEntity 看起来怎么样?方法需要单个实体可能是问题,但您提供了一个列表。请编辑问题以提供EmployeeEntity 类。谢谢。
  • EmployeeEntity 看起来像 db 的表结构它是这个项目的模型。它包含所有列字段的 getter 和 setter。谢谢!!

标签: spring-boot


【解决方案1】:

查看github链接后发现jackson需要在pom.xml中指定

<dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.10.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.10.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.10.1</version>
        </dependency>

【讨论】:

  • 你好兄弟!它给出了一些随机值,例如“com.adkdinesh.template.entity.EmployeeEntity@7a6a7007”@7a6a7007=?
  • 我需要开发rest api ...在我的情况下,Json 不被spring接受..但我不知道是什么问题
  • 它调用实体的toString()方法。现在什么不工作?
  • 它返回空值到每个字段兄弟!。它使休眠的内容违规错误
  • 所以这意味着它现在与 415 无关。请检查您的请求正文和字段是否匹配
猜你喜欢
  • 1970-01-01
  • 2019-08-22
  • 2019-09-01
  • 2021-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-14
  • 1970-01-01
相关资源
最近更新 更多