简体   繁体   中英

can we receive @RequestParam in object

@RequestParam(value = "searchData", required = false) SearchData searchData) 

searchData is having 2 variables of string type one for accepting param value and one for search parameter,but it is showing that conversion type error cant convert string to object, and it is showing that parameter received is null .

To achieve this, you should define the controller method without annotation

@RequestParam(value = "searchData", required = false)

Just use: (SearchData searchData)

When called with no parameters, the object searchData will have all attributes set to null.

All attributes will be set to null, also in case if you use a parameter name that is not equal to one of the attribute names of SearchData . For example in the case of misspelling (you have SearchData.name, and in call you have used names='someanme'). No error will be thrown.

you need to use RequestBody annotaion and provide value in the form of json object.

@RequestBody SearchData searchData

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM