背景:
在controller
层中的一个get
请求有多个参数,为避免写多个@RequestParam
导致代码阅读体验下降,故将这些请求参数封装成一个pojo
对象,属性名与参数名对应(不对应无法成功接收)。
示例代码:
@RequestMapping("/test")
public Result test(CommonModel model) {
System.out.println(model);
...
}
public class CommonModel {
private Integer param1;
private String param2;
...
}
问题描述
发起请求后,打印的model
属性值都是null
CommonModel{param1=null,param2=null,...}
原因:
检查后发现CommonModel
中漏写了getter
和setter
方法,请求传递的参数没办法被model
接收。