今天遇到一个小问题:
number是Bean的一个属性。SpringMVC自动封装。
今天突然发现新增的几条数据请求时报400了,但之前的数据是没问题的。
//jQuery代码片段
$.post('${pageContext.request.contextPath}/xxx/doXxx',{'number':number},function(data){})
//SpringMvc - Controller 代码片段
@RequestMapping(value = "doXxx", method = RequestMethod.POST)
@ResponseBody
public void doXxx(HttpServletResponse response, Bean obj) {
//PrintWriter.print(selectBean(obj)) -- 伪代码:通过bean(number)查询数据 然后封装成json扔回前台
}
对比之后发现,新生成的number的位数较之前的要长( 原来4位,现为13位);
原来昨天根据需要修改了number的生成规则(加长了),但此处的Bean中的number是Integer类型,
所以服务端面对前台过来的参数,不能以规定的类型接收,就报400了。
将Bean中的number改为Long/String,让服务器以合适的类型接收参数,就可以了。