springboot中的controller參數(shù)映射問題小結(jié)
我用來接收參數(shù)的類、json參數(shù)為下面展示
public class ExtendedInformation { String customerItemName; String operation; public String getWaferLot() { return customerItemName; } public void setWaferLot(String customerItemName) { this.customerItemName = customerItemName; } public String getOperation() { return operation; } public void setOperation(String operation) { this.operation = operation; } }
{ "operation": "TEST", "customerItemName": "TEST" }
然后發(fā)現(xiàn),customerItemName參數(shù)映射不上
原來是我的customerItemName屬性的getter,setter方法名getWaferLot/setWaferLot,而我的json參數(shù)里沒有waferLot,導(dǎo)致映射不上。
改為下面的json參數(shù),就能成功映射。
{ "operation": "TEST", "waferLot": "TEST" }
總結(jié):參數(shù)映射時(shí),是根據(jù)我們發(fā)送的參數(shù)名找到對應(yīng)的setter方法,進(jìn)行屬性賦值
1.如果我們用lombok注解會(huì)生成對象屬性名對應(yīng)的getter/setter方法,我們的發(fā)送參數(shù)只要跟對象屬性名就可以了
2.如果我們自定義setter方法,要確保我們的發(fā)送參數(shù)能與setter方法映射上,例如setxxx和{'xxx':''}
到此這篇關(guān)于springboot的controller參數(shù)映射問題的文章就介紹到這了,更多相關(guān)springboot controller參數(shù)映射內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- SpringBoot如何實(shí)現(xiàn)調(diào)用controller和Service層方法
- springboot中Controller內(nèi)文件上傳到本地及阿里云操作方法
- springboot如何通過controller層實(shí)現(xiàn)頁面切換
- springboot Controller直接返回String類型帶來的亂碼問題及解決
- SpringBoot之controller參數(shù)校驗(yàn)詳解
- springboot中@RestController注解實(shí)現(xiàn)
- SpringBoot通過注解監(jiān)測Controller接口的代碼示例
- springboot controller參數(shù)注入方式
- SpringBoot中@RestControllerAdvice @ExceptionHandler異常統(tǒng)一處理類失效原因分析
- SpringBoot和MybatisPlus實(shí)現(xiàn)通用Controller示例
相關(guān)文章
spring項(xiàng)目如何配置多數(shù)據(jù)源(已上生產(chǎn),親測有效)
這篇文章主要介紹了spring項(xiàng)目如何配置多數(shù)據(jù)源(已上生產(chǎn),親測有效),具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12Java比較器實(shí)現(xiàn)方法項(xiàng)目案例
這篇文章主要介紹了Java比較器實(shí)現(xiàn)方法,結(jié)合具體項(xiàng)目案例形式分析了Java比較器相關(guān)排序操作技巧,需要的朋友可以參考下2019-03-03Java技巧函數(shù)方法實(shí)現(xiàn)二維數(shù)組遍歷
這篇文章主要介紹了Java技巧函數(shù)方法實(shí)現(xiàn)二維數(shù)組遍歷,二維數(shù)組遍歷,每個(gè)元素判斷下是否為偶數(shù),相關(guān)內(nèi)容需要的小伙伴可以參考一下2022-08-08Java中print、printf、println的區(qū)別
這篇文章主要介紹了Java中print、printf、println的區(qū)別的相關(guān)資料,需要的朋友可以參考下2023-03-03MyBatis實(shí)現(xiàn)批量插入方法實(shí)例
最近在公司項(xiàng)目開發(fā)中遇到批量數(shù)據(jù)插入或者更新,下面這篇文章主要給大家介紹了關(guān)于MyBatis實(shí)現(xiàn)批量插入的相關(guān)資料,需要的朋友可以參考下2022-10-10