spring boot中post請求接收引數

2021-09-29 12:44:31 字數 613 閱讀 8764

spring boot遇坑記

引數直接寫long id一直報錯。調整為long id後 拿到的結果一直是null。

引數需要加@requestbody

如只傳乙個id,必須要封裝到乙個物件中,可以用jsonobject ,也可以自定義乙個param物件。

("/city"

)public city city

(@requestbody jsonobject json)

(value =

"/city2"

, method = requestmethod.post)

public city city2

(@requestbody cityparam cityparam)

{return cityservice.

getbyid

(cityparam.

getid()

);使用postman測試

springboot 對post請求中的引數解密

之所以這裡只提到解密,是因為加密在vue前端已經實現了,前端返給後端的就是加密後的物件,而後端只負責解密就行了。如果需要後端進行加密,建議在responsebodyadvice中進行。apioperationsupport author apiauthor.wenhao apioperation v...

Springboot中Thymeleaf外部模板

spingboot專案中,預設的thymeleaf模板資料夾是在 src main resources templates,打包時後在classpath templates下 jar包同目錄下的 templates 目錄 spring.thymeleaf.prefix file templates ...

springboot中controller無法訪問

configuration 該註解將類可以看成配置檔案,通常和 bean配合使用 enableautoconfiguration 在程式啟動時自動載入配置 componentscan 會自動掃瞄指定包下的全部標有 component的類,並註冊成bean,當然包括 component下的子註解 se...