国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing

這篇具有很好參考價(jià)值的文章主要介紹了org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

報(bào)錯(cuò)信息

org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public cn.hp.util.Result cn.hp.controller.ValidateCode.sendSMS(java.lang.String)

控制臺(tái)輸出的是缺少必須的請(qǐng)求正文
發(fā)現(xiàn)從前端 走的請(qǐng)求 攜帶一個(gè)參數(shù) 到后端沒(méi)有接收到

前端代碼

  axios.post("http://127.0.0.1:8080/validateCode/send4Order/" + telephone).then(res => {}

后端代碼

//發(fā)送驗(yàn)證碼
@RestController
@RequestMapping("/validateCode")
public class ValidateCode {

    @PostMapping(value = "/send4Order/{telephone}")
 public Result sendSMS(@RequestBody String telephone) {

 }

原因:
報(bào)錯(cuò)時(shí):后臺(tái)代碼使用@RequestBody 注解報(bào)錯(cuò)i 前端發(fā)送請(qǐng)求,沒(méi)有進(jìn)這個(gè)controller
把@RequestBody 換成 @PathVariable 就好了

@RestController
@RequestMapping("/validateCode")
public class ValidateCode {

    @PostMapping(value = "/send4Order/{telephone}")
     public Result sendSMS(@PathVariable String telephone) {
     
     }

@RequestBody

注解@RequestBody接收的參數(shù)是來(lái)自requestBody中,即請(qǐng)求體。

主要用來(lái)接收前端傳遞給后端的json字符串中的數(shù)據(jù)的(請(qǐng)求體中的數(shù)據(jù)的)

最常用的請(qǐng)求體傳參是POST請(qǐng)求,所以使用@RequestBody接收數(shù)據(jù)時(shí),一般都用POST方式進(jìn)行提交。

請(qǐng)求方式

  • GET請(qǐng)求中,因?yàn)闆](méi)有HttpEntity,所以@RequestBody并不適用。
  • POST請(qǐng)求中,通過(guò)HttpEntity傳遞的參數(shù),必須要在請(qǐng)求頭中聲明數(shù)據(jù)的類型Content-Type,

@RequestParam

注解@RequestParam接收的參數(shù)是來(lái)自requestHeader中,即請(qǐng)求頭。

接收的參數(shù)是來(lái)自HTTP請(qǐng)求體或請(qǐng)求url的QueryString中。

RequestParam可以接受簡(jiǎn)單類型的屬性,也可以接受對(duì)象類型。

實(shí)質(zhì)是將Request.getParameter() 中的Key-Value參數(shù)Map利用Spring的轉(zhuǎn)化機(jī)制ConversionService配置,轉(zhuǎn)化成參數(shù)接收對(duì)象或字段。

如果在請(qǐng)求中指定contentType: 'application/json;charset=UTF-8’時(shí)會(huì)出現(xiàn)400錯(cuò)誤文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-436784.html

@RequestParam有三個(gè)配置參數(shù):

  • required 表示是否必須,默認(rèn)為 true,必須。
  • defaultValue 可設(shè)置請(qǐng)求參數(shù)的默認(rèn)值。
  • value 為接收url的參數(shù)名(相當(dāng)于key值)。

區(qū)別

  • 在后端的同一個(gè)接收方法里,@RequestBody與@RequestParam()可以同時(shí)使用
  • @RequestBody最多只能有一個(gè),而@RequestParam()可以有多個(gè)。

總結(jié)

  • 在GET請(qǐng)求中,不能使用@RequestBody。
  • 在POST請(qǐng)求,可以使用@RequestBody和@RequestParam,但是如果使用@RequestBody,對(duì)于參數(shù)轉(zhuǎn)化的配置必須統(tǒng)一。
  • 如果使用@RequestParam來(lái)接受參數(shù),可以在接受參數(shù)的model中設(shè)置@DateFormat指定所需要接受時(shí)間參數(shù)的格式。
  • 在使用@RequestParam,不能指定contentType: ‘a(chǎn)pplication/json; charset=UTF-8’
  • 另外,使用@RequestBody接受的參數(shù)是不會(huì)被Servlet轉(zhuǎn)化統(tǒng)一放在request對(duì)象的Param參數(shù)集中,@RequestParam是可以的。
  • 一般情況下,推薦使用@RequestParam注解來(lái)接受Http請(qǐng)求參數(shù)。

POST請(qǐng)求時(shí)

  • @RequestBody --> JSON字符串部分
  • @RequestParam --> 請(qǐng)求參數(shù)部分
  • application/json格局圖
  • form-data、x-www-form-urlencoded格局圖

到了這里,關(guān)于org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter for

    SpringBoot請(qǐng)求接口報(bào)錯(cuò) 這是我的實(shí)體類 可以發(fā)現(xiàn)我的實(shí)體類并沒(méi)有set和get方法才會(huì)報(bào)錯(cuò) HttpMediaTypeNotAcceptableException 修改之后添加set和get方法,可以成功運(yùn)行

    2024年02月12日
    瀏覽(19)
  • 解決報(bào)錯(cuò):@org.springframework.beans.factory.annotation.Autowired(required=true)

    先把問(wèn)題貼出來(lái): @org.springframework.beans.factory.annotation.Autowired(required=true) 報(bào)這個(gè)錯(cuò)是因?yàn)椋?@Autowired(required=true):當(dāng)使用@Autowired注解的時(shí)候,其實(shí)默認(rèn)就是@Autowired(required=true),表示注入的時(shí)候,該bean必須存在,否則就會(huì)注入失敗。 ** ** 解決辦法:

    2024年02月13日
    瀏覽(21)
  • 【錯(cuò)誤】A component required a bean of type ‘org.springframework.security.config.annotation.ObjectPostPr

    【錯(cuò)誤】A component required a bean of type ‘org.springframework.security.config.annotation.ObjectPostPr

    Description: A component required a bean of type \\\'org.springframework.security.config.annotation.ObjectPostProcessor\\\' that could not be found. Action: Consider defining a bean of type \\\'org.springframework.security.config.annotation.ObjectPostProcessor\\\' in your configuration. ? 描述: 組件需要“org.springframework.security.configannotation”類型的

    2024年02月13日
    瀏覽(22)
  • HttpMessageNotReadableException: Required request body is missing:

    HttpMessageNotReadableException: Required request body is missing:

    完整錯(cuò)誤: Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public java.lang.Object com.example.sx.study.Econtroller.test1(com.example.sx.study.Entity,org.springframework.validation.BindingResult)] 解決辦法: 在@RequestBody后加上( required = false ) 雖然通過(guò)此方法的確返回了

    2023年04月08日
    瀏覽(13)
  • 已解決org.springframework.beans.factory.UnsatisfiedDependencyException org.springframework.beans.factor

    已解決org.springframework.beans.factory.UnsatisfiedDependencyException org.springframework.beans.factory.異常的正確解決方法,親測(cè)有效?。。?org.springframework.beans.factory.UnsatisfiedDependencyException org.springframework.beans.factor 對(duì)于 org.springframework.beans.factory.UnsatisfiedDependencyException 異常,通常是由于依賴注

    2024年02月05日
    瀏覽(20)
  • org.springframework.context.ApplicationContextException: Failed to start bean ‘org.springframework.a

    使用RabbitMq測(cè)試交換機(jī)、隊(duì)列時(shí)候報(bào)的錯(cuò) 一開(kāi)始我以為是隊(duì)列的監(jiān)聽(tīng)器配置信息和監(jiān)聽(tīng)器代碼寫(xiě)錯(cuò)了,反復(fù)查看并沒(méi)有錯(cuò)誤。 然后繼續(xù)往下看報(bào)錯(cuò),有這倆報(bào)錯(cuò),瞬間頓悟。 ACCESS_REFUSED 這么大個(gè)字,看了好幾遍居然沒(méi)想到這方面的錯(cuò)誤,大概是配置密碼的時(shí)候copy錯(cuò)了 hotel

    2024年02月15日
    瀏覽(44)
  • 報(bào)錯(cuò):org.springframework.jdbc.BadSqlGrammarException:

    報(bào)錯(cuò):org.springframework.jdbc.BadSqlGrammarException:

    //報(bào)錯(cuò) 2024-02-24 19:44:10.814 ERROR 6184 --- [nio-9090-exec-5] c.e.exception.GlobalExceptionHandler ? ? : 異常信息: org.springframework.jdbc.BadSqlGrammarException:? 根據(jù)異常信息,這是一個(gè)Spring框架拋出的`BadSqlGrammarException`異常,通常這個(gè)異常表示SQL語(yǔ)法錯(cuò)誤。 要解決這個(gè)問(wèn)題,你需要做以下幾步:

    2024年04月10日
    瀏覽(23)
  • org.springframework.data.mongodb.UncategorizedMongoDbException

    org.springframework.data.mongodb.UncategorizedMongoDbException: Runner error: Overflow sort stage buffered data usage of 33700095 bytes exceeds internal limit of 33554432 bytes; nested exception is com.mongodb.MongoException: Runner error: Overflow sort stage buffered data usage of 33700095 bytes exceeds internal limit of 33554432 bytes 這個(gè)異常通常會(huì)在

    2024年02月12日
    瀏覽(18)
  • 關(guān)于org.springframework.beans.factory.NoSuchBeanDefinitionException

    關(guān)于org.springframework.beans.factory.NoSuchBeanDefinitionException

    這個(gè)報(bào)錯(cuò)可能是因?yàn)椋?1. spring的xml配置文件Bean中的id和getBean的id不一致 spring的配置文件中: 而程序中 applicationContext.getBean(“studenta”, Student.class)中的是studenta而spring配置文件的id是student,不一致。 2. 是否是忘記加注解了 @Resource或@Autowired都可以(@Resource是jdk自帶的) 3.如果

    2024年02月13日
    瀏覽(18)
  • org.springframework.util.StopWatch使用說(shuō)明

    StopWatch是一個(gè)簡(jiǎn)單實(shí)用的秒表工具類,可以用來(lái)評(píng)估代碼塊的執(zhí)行時(shí)間和性能。 以下是StopWatch的主要用法: 創(chuàng)建StopWatch對(duì)象 啟動(dòng)秒表計(jì)時(shí) 執(zhí)行需要計(jì)時(shí)的代碼塊 停止秒表計(jì)時(shí) 獲取執(zhí)行時(shí)間 間隔計(jì)時(shí) 可以通過(guò)多次調(diào)用start()和stop()進(jìn)行間隔計(jì)時(shí)。 例如: 然后可以通過(guò)getTaskTim

    2024年02月03日
    瀏覽(19)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包