我用来接收参数的类、json参数为下面展示
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" }
然后发现,customeritemname参数映射不上
原来是我的customeritemname属性的getter,setter方法名getwaferlot/setwaferlot,而我的json参数里没有waferlot,导致映射不上。
改为下面的json参数,就能成功映射。
{ "operation": "test", "waferlot": "test" }
总结:参数映射时,是根据我们发送的参数名找到对应的setter方法,进行属性赋值
1.如果我们用lombok注解会生成对象属性名对应的getter/setter方法,我们的发送参数只要跟对象属性名就可以了
2.如果我们自定义setter方法,要确保我们的发送参数能与setter方法映射上,例如setxxx和{'xxx':''}
到此这篇关于springboot的controller参数映射问题的文章就介绍到这了,更多相关springboot controller参数映射内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论