简体   繁体   English

我们可以在 object 中接收@RequestParam

[英]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 . searchData有 2 个字符串类型的变量,一个用于接受参数值,一个用于搜索参数,但显示转换类型错误无法将字符串转换为 object,并且显示收到的参数为null

To achieve this, you should define the controller method without annotation为此,您应该定义不带注释的 controller 方法

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

Just use: (SearchData searchData)只需使用: (SearchData searchData)

When called with no parameters, the object searchData will have all attributes set to null.当不带参数调用时,object searchData将所有属性设置为 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 .所有属性都将设置为 null,如果您使用的参数名称不等于SearchData的属性名称之一。 For example in the case of misspelling (you have SearchData.name, and in call you have used names='someanme').例如,在拼写错误的情况下(您有 SearchData.name,并且在通话中您使用了 names='someanme')。 No error will be thrown.不会抛出任何错误。

you need to use RequestBody annotaion and provide value in the form of json object.您需要使用 RequestBody 注释并以 json object 的形式提供值。

@RequestBody SearchData searchData

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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