http://blog.csdn.net/z69183787/article/details/40375831

遇到的问题:

1 条件:

1.1、表单里有两个时间参数,都是作为隐藏项随表单一起提交:

<input name="createTime" id="createTime" type="hidden" />
<input name="lastTime" id="lastTime" type="hidden" />

1.2、在表单对应的model类User中,对createTime使用了时间格式转换,对lastTime没有使用。

@JsonSerialize(using = CustomDateSerializer.class)
public Date getCreateTime() {
return createTime;
} public Date getLastTime() {
return lastTime;
}

2 产生问题:在使用jQuery提交表单时,无法提交到后台controller。

$(function() {
$("#form").form({
url :"${pageContext.request.contextPath}/systemManage/saveUser",
onSubmit : function() {
parent.$.messager.progress({
title : '提示',
text : '数据处理中,请稍后....'
});
var isValid = $(this).form('validate');
if (!isValid) {
parent.$.messager.progress('close');
}
return isValid;
},
success : function(result) {
parent.$.messager.progress('close');
result = $.parseJSON(result);
if (result.status) {
parent.reload;
parent.$.modalDialog.openner.datagrid('reload');
parent.$.modalDialog.handler.dialog('close');
parent.$.messager.show({
title : result.title,
msg : result.message,
timeout : 1000 * 2
});
}else{
parent.$.messager.show({
title : result.title,
msg : result.message,
timeout : 1000 * 2
});
}
}
});
});

在/systemManage/saveUser对应controller方法中打断点无法走入,即无法触发controller方法,但奇怪的是,我的集成了HandlerInterceptorAdapter的拦截器可拦截到url。随后js进入success分支。

3 调查问题,

3.1 发现形如下列的表单项可以提交表单

<input name="createTime" id="createTime" type="hidden" value="2016-06-21 17:24:19">

<input name="lastTime" id="lastTime" type="hidden" value="">

3.2 而形如下列的表单无法提交

<input name="createTime" id="createTime" type="hidden" value="2016-06-21 17:24:19">

<input name="lastTime" id="lastTime" type="hidden" value="14363774849">

3.3 怀疑是lastTime的提交导致的问题,尝试将getLastTime加上时间格式,问题解决。理由不清楚。

@JsonSerialize(using = CustomDateSerializer.class) 

public Date getLastTime() {
return lastTime;
}

3.4 后记,将日期类型的input都使用@JsonSerialize修改日期格式以后,表单彻底无法提交了,3.1中描述的现象也无法重现。

或许是我使用了jquery.easyui.min.js的表单提交函数.form。

<script type="text/javascript">
$(function() {
$("#form").form({
url : "${pageContext.request.contextPath}/systemManage/saveUser",
onSubmit : function() {
parent.$.messager.progress({
title : '提示',
text : '数据处理中,请稍后....'
});
var isValid = $(this).form('validate');
if (!isValid) {
parent.$.messager.progress('close');
}
return isValid;
},
success : function(result) {
parent.$.messager.progress('close');
result = $.parseJSON(result);
if (result.status) {
parent.reload;
parent.$.modalDialog.openner.datagrid('reload');
parent.$.modalDialog.handler.dialog('close');
parent.$.messager.show({
title : result.title,
msg : result.message,
timeout : 1000 * 2
});
} else {
parent.$.messager.show({
title : result.title,
msg : result.message,
timeout : 1000 * 2
});
}
}
});
});
</script>

所谓的表单无法提交的具体表现是,onSubmit执行以后,无法触发url指定的后台程序,程序直接走进success分支中,如果将result参数打印出来会发现,这是个400出错界面,

出错信息的大概意思是,js在组织request的时候出错,所以肯定无法触发后台程序了。

解决的办法就是删除表单中的日期类型的input,彻底解决的办法还未找到。

SpringMVC使用@ResponseBody时返回json的日期格式及可能产生的问题的更多相关文章

  1. [转]SpringMVC使用@ResponseBody时返回json的日期格式、@DatetimeFormat使用注意

    一.SpringMVC使用@ResponseBody时返回json的日期格式 前提了解: @ResponseBody 返回json字符串的核心类是org.springframework.http.co ...

  2. SpringMVC使用@ResponseBody时返回json的日期格式、@DatetimeFormat使用注意

    一.SpringMVC使用@ResponseBody时返回json的日期格式 前提了解: @ResponseBody 返回json字符串的核心类是org.springframework.http.co ...

  3. springmvc学习笔记--json--返回json的日期格式问题

    (一)输出json数据 springmvc中使用jackson-mapper-asl即可进行json输出,在配置上有几点: 1.使用mvc:annotation-driven 2.在依赖管理中添加ja ...

  4. spring Mvc json返回json的日期格式问题

    (一)输出json数据 springmvc中使用jackson-mapper-asl即可进行json输出,在配置上有几点: 1.使用mvc:annotation-driven 2.在依赖管理中添加ja ...

  5. 解决springmvc使用ResponseBody注解返回json中文乱码问题

    spring版本:4.2.5.RELEASE 查看“org.springframework.http.converter.StringHttpMessageConverter”源码,中有一段说明: B ...

  6. SpringMVC 利用@ResponseBody注解返回Json时,出现406 not acceptable 错误的解决方法。

    1 在RequestMapping中加入produces属性如: @RequestMap(value="/path",produces="application/json ...

  7. 【原】:关于使用springmvc的responseBody注解返回json的一些总结

    配置不正确可能会出现406错误 1:首先需要导入三个jar包: 2:需要在springmvc的配置文件文件中添加转换器并开启注解驱动: 3:controller:这里返回object也是可以的; 4: ...

  8. spingmvc 返回json数据日期格式化方法

    第一种: json 用的是这个依赖 <!-- JSON lib 开发包 以及它的依赖包 --> <dependency> <groupId>com.fasterxm ...

  9. SpringMVC 避免IE执行AJAX时,返回JSON出现下载文件

    <?xml version="1.0" encoding="UTF-8"?> <!-- SpringMVC配置文件 --> <be ...

随机推荐

  1. Spark内存管理之钨丝计划

    Spark内存管理之钨丝计划 1. 钨丝计划的产生的原因 2. 钨丝计划内幕详解  一:“钨丝计划”产生的本质原因 1, Spark作为一个一体化多元化的(大)数据处理通用平台,性能一直是其根本性的追 ...

  2. oozie 重新提交作业

    在oozie的运行过程当中可能会出现错误,比如数据库连接不上,或者作业执行报错导致流程进入suspend或者killed状态,这个时候我们就要分析了,如果确实是数据或者是网络有问题,我们比如把问题解决 ...

  3. 微信小程序——极点日历使用方法

    极点日历github项目地址 添加至自己的小程序方法 极点日历属性接口文档 代码实例: xml: <calendar calendar-style="calendar" he ...

  4. 关于Unity中的道具拾取(专题六)

    原理就是把道具做成触发器,触发器就是当我们有碰撞发生的时候,只会检测碰撞,而不会有任何改变物理运动状态的过程. 触发器非常适合道具拾取,因为它不会改变原本运动物体的任何物理属性,但是依然会检测碰撞,响 ...

  5. SSH-运行main函数,一直报空指针,调依赖注入配置的dao

    解决this.getHibernateTemplate()==null的问题 刚刚在整合SSH时碰到了这样一个问题: 当我用junit测试时不会报任何异常,数据也都能得到 但当我运行man函数,直接n ...

  6. (笔记)AES加密在线计算工具

    AES加密在线计算工具: http://aes.online-domain-tools.com/

  7. mysql 合理创建索引

    场景: KEY `index_gscode_f4_f7` (`gscode`,`f4`,`f7`) USING BTREE KEY `index_gscode_f7_f4` (`gscode`,`f7 ...

  8. 通配符的匹配很全面, 但无法找到元素 'context:property-placeholder'

    解决方案就是如下: xmlns:context="http://www.springframework.org/schema/context" 同时在xsi:schemaLocat ...

  9. (转)FFmpeg源代码简单分析:avformat_find_stream_info()

    目录(?)[+] ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结 ...

  10. Python——getpass

    getpass模块提供了可移植的密码输入,一共包括下面两个函数: 1. getpass.getpass() 2. getpass.getuser() getpass.getpass([prompt[, ...