SpringMVC使用@ResponseBody时返回json的日期格式及可能产生的问题
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的日期格式及可能产生的问题的更多相关文章
- [转]SpringMVC使用@ResponseBody时返回json的日期格式、@DatetimeFormat使用注意
一.SpringMVC使用@ResponseBody时返回json的日期格式 前提了解: @ResponseBody 返回json字符串的核心类是org.springframework.http.co ...
- SpringMVC使用@ResponseBody时返回json的日期格式、@DatetimeFormat使用注意
一.SpringMVC使用@ResponseBody时返回json的日期格式 前提了解: @ResponseBody 返回json字符串的核心类是org.springframework.http.co ...
- springmvc学习笔记--json--返回json的日期格式问题
(一)输出json数据 springmvc中使用jackson-mapper-asl即可进行json输出,在配置上有几点: 1.使用mvc:annotation-driven 2.在依赖管理中添加ja ...
- spring Mvc json返回json的日期格式问题
(一)输出json数据 springmvc中使用jackson-mapper-asl即可进行json输出,在配置上有几点: 1.使用mvc:annotation-driven 2.在依赖管理中添加ja ...
- 解决springmvc使用ResponseBody注解返回json中文乱码问题
spring版本:4.2.5.RELEASE 查看“org.springframework.http.converter.StringHttpMessageConverter”源码,中有一段说明: B ...
- SpringMVC 利用@ResponseBody注解返回Json时,出现406 not acceptable 错误的解决方法。
1 在RequestMapping中加入produces属性如: @RequestMap(value="/path",produces="application/json ...
- 【原】:关于使用springmvc的responseBody注解返回json的一些总结
配置不正确可能会出现406错误 1:首先需要导入三个jar包: 2:需要在springmvc的配置文件文件中添加转换器并开启注解驱动: 3:controller:这里返回object也是可以的; 4: ...
- spingmvc 返回json数据日期格式化方法
第一种: json 用的是这个依赖 <!-- JSON lib 开发包 以及它的依赖包 --> <dependency> <groupId>com.fasterxm ...
- SpringMVC 避免IE执行AJAX时,返回JSON出现下载文件
<?xml version="1.0" encoding="UTF-8"?> <!-- SpringMVC配置文件 --> <be ...
随机推荐
- CentOS重置Mysql密码
1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...
- AJAX 简单例程示例
index.html <html> <head> <script> function showHint(str) { if (str.length==0) { re ...
- CPP_封装_继承_多态
类的三方法:封装,继承,多态.封装:使用一整套方法去创建一个新的类型,这叫类的封装.继承:从一个现有的类型基础上,稍作改动,得到一个新的类型的方法,叫类的继承.多态:当有几个不同的子类对象时,对象调用 ...
- python使用pip离线安装库
一.前言及环境 1. 场景及整体思路 最近在做一个大数据项目,开发过程中用自己的机子安装了很多库,开发完之后需要部署到客户那边的环境中,但是客户那边的环境是不能联网的,于是就需要离线进行库的安装. 上 ...
- metrics 开发监控实现jdbc
Metrics 主要有五大基本组件1:Counter 记录执行次数2:Gauge 获取某个值3:Meter 用来计算事件的速率4:Histogram 可以为数据流提供统计数据. 除了最大值,最 ...
- JVM调优总结(一):基本概念
一.数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型. 基本类型的变量保存原始值,即:他代表的值就是数值本身: 而引用类型的变量保存引用值.“引用值”代表了某个对象的引用,而不是对 ...
- MFC函数—— CFrameWnd::OnCreateClient
CFrameWnd::OnCreateClient virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext*pContext); ...
- js学习(一)-对象和函数概念
//-----------------------js代码-------------------- function class1(){ //类成员的定义及构造函数 this.name = ...
- Mac和Linux下pip更换源
cd ~mkdir .pip vim .pip/pip.conf 在pip.conf中写入 [global]timeout = 6000index-url = https://pypi.tuna.ts ...
- savReaderWriter 模块的使用
作用: 由于python可以辅助数据分析和数据挖掘,读取文件, 而savReaderWriter模块就是为此而设计. 官网 :http://pythonhosted.org/savReaderWrit ...