您的位置:首页 > 理论基础 > 计算机网络

jquery ajax 报交请求返回 HTTP 400 错误

2016-03-24 10:49 381 查看
提交请求的AJAX代码如下:

点击(此处)折叠或打开

$.ajax({

url: "${ctx}/selfhelp/userAttributeAnalysis/userAttributeList",

type: "POST",

data:{appId:appId,

type:type,

startDate:startDate,

endDate:endDate,

deviceType:deviceType,

displayType:displayType},

dataType: "json",

success: paddinglist

});

里面data是传的一些参数。

ACTION使用的是SpringMVC的注解方式,接收方法如下:

点击(此处)折叠或打开

@RequestMapping(value = "/userAttributeList")

@ResponseBody

public List<UserAttribute> userAttributeList(HttpServletRequest request,

int type, String appId, int deviceType, int displayType,

Date startDate, Date endDate, ModelMap modelMap) throws Exception {

。。。。。。。。

}

接收的地方也接收了这些参数,但通过DEBUG看,根本就没到这个方法里,在外层就抛错了。
于是我Debug在DispatcherServlet上,发现在框架自动填充Date类型时,使用的格式是"yyyy-MM-dd HH:mm:ss",是在父类里有以下代码:

点击(此处)折叠或打开

@InitBinder

public void initBinder(ServletRequestDataBinder binder)

{

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));

}

但我在WEB上设置的日期,格式是yyyy-MM-dd。
原来如此,那解决办法就显而易见了。可以在ajax里将时间传入时加入时分秒,也可以改initBinder。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: