Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body

Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body,第1张

Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body idea报错信息:Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public boolean com.reap.demo.controller.CRUDController.updateById(com.reap.demo.domain.User)]

idea报错信息:Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public boolean com.reap.demo.controller.CRUDController.updateById(com.reap.demo.domain.User)]

idea报错信息如下:

"C:Program FilesJavajdk1.8.0_191binjava.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always "-javaagent:D:JavaTOOLJetBrainsIntelliJ IDEA 2020.3.4libidea_rt.jar=63142:D:JavaTOOLJetBrainsIntelliJ IDEA 2020.3.4bin" -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_191jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_191jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_191jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_191jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_191jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_191jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_191jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_191jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_191jrelibextnashorn.jar;C:Program FilesJavajdk1.8.0_191jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_191jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_191jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_191jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_191jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_191jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_191jrelibjce.jar;C:Program FilesJavajdk1.8.0_191jrelibjfr.jar;C:Program FilesJavajdk1.8.0_191jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_191jrelibjsse.jar;C:Program FilesJavajdk1.8.0_191jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_191jrelibplugin.jar;C:Program FilesJavajdk1.8.0_191jrelibresources.jar;C:Program FilesJavajdk1.8.0_191jrelibrt.jar;D:JavaCODEReaptargetclasses;D:JavaMAVENreporgspringframeworkbootspring-boot-starter2.4.5spring-boot-starter-2.4.5.jar;D:JavaMAVENreporgspringframeworkbootspring-boot2.4.5spring-boot-2.4.5.jar;D:JavaMAVENreporgspringframeworkspring-context5.3.6spring-context-5.3.6.jar;D:JavaMAVENreporgspringframeworkbootspring-boot-autoconfigure2.4.5spring-boot-autoconfigure-2.4.5.jar;D:JavaMAVENreporgspringframeworkbootspring-boot-starter-logging2.4.5spring-boot-starter-logging-2.4.5.jar;D:JavaMAVENrepchqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;D:JavaMAVENrepchqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;D:JavaMAVENreporgapachelogginglog4jlog4j-to-slf4j2.13.3log4j-to-slf4j-2.13.3.jar;D:JavaMAVENreporgapachelogginglog4jlog4j-api2.13.3log4j-api-2.13.3.jar;D:JavaMAVENreporgslf4jjul-to-slf4j1.7.30jul-to-slf4j-1.7.30.jar;D:JavaMAVENrepjakartaannotationjakarta.annotation-api1.3.5jakarta.annotation-api-1.3.5.jar;D:JavaMAVENreporgspringframeworkspring-core5.3.6spring-core-5.3.6.jar;D:JavaMAVENreporgspringframeworkspring-jcl5.3.6spring-jcl-5.3.6.jar;D:JavaMAVENreporgyamlsnakeyaml1.27snakeyaml-1.27.jar;D:JavaMAVENrepnetbytebuddybyte-buddy1.10.22byte-buddy-1.10.22.jar;D:JavaMAVENreporgspringframeworkbootspring-boot-starter-web2.4.5spring-boot-starter-web-2.4.5.jar;D:JavaMAVENreporgspringframeworkbootspring-boot-starter-json2.4.5spring-boot-starter-json-2.4.5.jar;D:JavaMAVENrepcomfasterxmljacksoncorejackson-databind2.11.4jackson-databind-2.11.4.jar;D:JavaMAVENrepcomfasterxmljacksoncorejackson-core2.11.4jackson-core-2.11.4.jar;D:JavaMAVENrepcomfasterxmljacksondatatypejackson-datatype-jdk82.11.4jackson-datatype-jdk8-2.11.4.jar;D:JavaMAVENrepcomfasterxmljacksondatatypejackson-datatype-jsr3102.11.4jackson-datatype-jsr310-2.11.4.jar;D:JavaMAVENrepcomfasterxmljacksonmodulejackson-module-parameter-names2.11.4jackson-module-parameter-names-2.11.4.jar;D:JavaMAVENreporgspringframeworkbootspring-boot-starter-tomcat2.4.5spring-boot-starter-tomcat-2.4.5.jar;D:JavaMAVENreporgapachetomcatembedtomcat-embed-core9.0.45tomcat-embed-core-9.0.45.jar;D:JavaMAVENreporgglassfishjakarta.el3.0.3jakarta.el-3.0.3.jar;D:JavaMAVENreporgapachetomcatembedtomcat-embed-websocket9.0.45tomcat-embed-websocket-9.0.45.jar;D:JavaMAVENreporgspringframeworkspring-web5.3.6spring-web-5.3.6.jar;D:JavaMAVENreporgspringframeworkspring-beans5.3.6spring-beans-5.3.6.jar;D:JavaMAVENreporgspringframeworkspring-webmvc5.3.6spring-webmvc-5.3.6.jar;D:JavaMAVENreporgspringframeworkspring-aop5.3.6spring-aop-5.3.6.jar;D:JavaMAVENreporgspringframeworkspring-expression5.3.6spring-expression-5.3.6.jar;D:JavaMAVENrepmysqlmysql-connector-java5.1.46mysql-connector-java-5.1.46.jar;D:JavaMAVENreporgprojectlomboklombok1.18.20lombok-1.18.20.jar;D:JavaMAVENreporgmybatismybatis3.5.0mybatis-3.5.0.jar;D:JavaMAVENreporgmybatisspringbootmybatis-spring-boot-starter1.2.0mybatis-spring-boot-starter-1.2.0.jar;D:JavaMAVENreporgspringframeworkbootspring-boot-starter-jdbc2.4.5spring-boot-starter-jdbc-2.4.5.jar;D:JavaMAVENrepcomzaxxerHikariCP3.4.5HikariCP-3.4.5.jar;D:JavaMAVENreporgspringframeworkspring-jdbc5.3.6spring-jdbc-5.3.6.jar;D:JavaMAVENreporgspringframeworkspring-tx5.3.6spring-tx-5.3.6.jar;D:JavaMAVENreporgmybatisspringbootmybatis-spring-boot-autoconfigure1.2.0mybatis-spring-boot-autoconfigure-1.2.0.jar;D:JavaMAVENreporgmybatismybatis-spring1.3.1mybatis-spring-1.3.1.jar;D:JavaMAVENrepiospringfoxspringfox-swagger22.7.0springfox-swagger2-2.7.0.jar;D:JavaMAVENrepioswaggerswagger-annotations1.5.13swagger-annotations-1.5.13.jar;D:JavaMAVENrepioswaggerswagger-models1.5.13swagger-models-1.5.13.jar;D:JavaMAVENrepcomfasterxmljacksoncorejackson-annotations2.11.4jackson-annotations-2.11.4.jar;D:JavaMAVENrepiospringfoxspringfox-spi2.7.0springfox-spi-2.7.0.jar;D:JavaMAVENrepiospringfoxspringfox-core2.7.0springfox-core-2.7.0.jar;D:JavaMAVENrepiospringfoxspringfox-schema2.7.0springfox-schema-2.7.0.jar;D:JavaMAVENrepiospringfoxspringfox-swagger-common2.7.0springfox-swagger-common-2.7.0.jar;D:JavaMAVENrepiospringfoxspringfox-spring-web2.7.0springfox-spring-web-2.7.0.jar;D:JavaMAVENreporgreflectionsreflections.9.11reflections-0.9.11.jar;D:JavaMAVENreporgjavassistjavassist3.21.0-GAjavassist-3.21.0-GA.jar;D:JavaMAVENrepcomgoogleguavaguava18.0guava-18.0.jar;D:JavaMAVENrepcomfasterxmlclassmate1.5.1classmate-1.5.1.jar;D:JavaMAVENreporgslf4jslf4j-api1.7.30slf4j-api-1.7.30.jar;D:JavaMAVENreporgspringframeworkpluginspring-plugin-core1.2.0.RELEASEspring-plugin-core-1.2.0.RELEASE.jar;D:JavaMAVENreporgspringframeworkpluginspring-plugin-metadata1.2.0.RELEASEspring-plugin-metadata-1.2.0.RELEASE.jar;D:JavaMAVENreporgmapstructmapstruct1.1.0.Finalmapstruct-1.1.0.Final.jar;D:JavaMAVENrepiospringfoxspringfox-swagger-ui2.7.0springfox-swagger-ui-2.7.0.jar;D:JavaMAVENrepcomalibabafastjson1.2.29fastjson-1.2.29.jar" com.reap.demo.DemoApplication

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |___, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.5)

2021-12-02 14:14:37.906  INFO 16556 --- [           main] com.reap.demo.DemoApplication            : Starting DemoApplication using Java 1.8.0_191 on DESKTOP-T0A53NA with PID 16556 (D:JavaCODEReaptargetclasses started by admin in D:JavaCODEReap)
2021-12-02 14:14:37.910  INFO 16556 --- [           main] com.reap.demo.DemoApplication            : No active profile set, falling back to default profiles: default
2021-12-02 14:14:39.753  INFO 16556 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
2021-12-02 14:14:39.766  INFO 16556 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-12-02 14:14:39.766  INFO 16556 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-12-02 14:14:39.890  INFO 16556 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-12-02 14:14:39.890  INFO 16556 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1860 ms
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
Using VFS adapter org.mybatis.spring.boot.autoconfigure.SpringBootVFS
Scanned package: 'com.aosiding.crud.domain' for aliases
Parsed mapper file: 'file [D:JavaCODEReaptargetclassescomreapdemomapperxmlCRUDMapper.xml]'
2021-12-02 14:14:40.649  INFO 16556 --- [           main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getdocumentation(String, HttpServletRequest)]
2021-12-02 14:14:40.724  INFO 16556 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-12-02 14:14:41.016  INFO 16556 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
2021-12-02 14:14:41.018  INFO 16556 --- [           main] d.s.w.p.documentationPluginsBootstrapper : Context refreshed
2021-12-02 14:14:41.038  INFO 16556 --- [           main] d.s.w.p.documentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2021-12-02 14:14:41.071  INFO 16556 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
2021-12-02 14:14:41.288  INFO 16556 --- [           main] com.reap.demo.DemoApplication            : Started DemoApplication in 4.122 seconds (JVM running for 5.551)
2021-12-02 14:15:41.343  INFO 16556 --- [nio-8888-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-12-02 14:15:41.344  INFO 16556 --- [nio-8888-exec-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-12-02 14:15:41.345  INFO 16556 --- [nio-8888-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@686ae92b] was not registered for synchronization because synchronization is not active
2021-12-02 14:15:41.459  INFO 16556 --- [nio-8888-exec-2] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-12-02 14:15:41.676  INFO 16556 --- [nio-8888-exec-2] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
JDBC Connection [HikariProxyConnection@1042020962 wrapping com.mysql.jdbc.JDBC4Connection@4dda5c] will not be managed by Spring
==>  Preparing: INSERT INTO user(id,name,password,createTime) values ( ?,?,?, now()) 
==> Parameters: null, 666(String), 666666(String)
<==    Updates: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@686ae92b]
2021-12-02 14:17:01.682  WARN 16556 --- [nio-8888-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public boolean com.reap.demo.controller.CRUDController.updateById(com.reap.demo.domain.User)]

代码如下:

package com.reap.demo.controller;

import com.reap.demo.domain.User;
import com.reap.demo.service.CRUDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class CRUDController {

    @Autowired
    private CRUDService crudService;

    
    @PostMapping("U")
    public boolean updateById(@RequestBody User user){
        boolean flag = crudService.updateById(user);
        return flag;
    }
}
解决方案如下:

解析:在后台方法参数上添加@RequestBody时,将请求参数封装成User对象时,需要JSON(application/json)格式解决:在Postman中如下设置即可正常访问,便于调试。

总结:
注意使用英文标点符号

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5638240.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存