这里提供三种解决方案。

一.局部转换 :只是对当前Controller类有效

springMVC.xml中添加:

  <bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="stringHttpMessageConverter" />
</list>
</property>
</bean>
<!-- String类型解析器,允许直接返回String类型的消息 -->
<bean id="stringHttpMessageConverter"
class="org.springframework.http.converter.StringHttpMessageConverter" />
<!-- 日期转换 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="com.rw.tools.ConvertDate"/>
</property>
</bean>
Controller 类文件中添加:
@Controller
@RequestMapping("/image")
public class ImageController { @Autowired
private ImageService imageService; @org.springframework.web.bind.annotation.InitBinder
public void InitBinder(WebDataBinder binder){
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
CustomDateEditor dateEditor = new CustomDateEditor(df, true);
binder.registerCustomEditor(Date.class,dateEditor);
}

二.全局转换

1.创建convertDate类实现WebBindingInitializer接口

public class convertDate implements WebBindingInitializer{

    @Override
public void initBinder(WebDataBinder binder, WebRequest request) {
// TODO Auto-generated method stub
//转换日期
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
}

2.在Spring-MVC.xml中配置日期转换

<!-- 日期转换 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="com.wx.web.convertDate"/>
</property>
</bean>

三.实体类属性方法配置

 @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")//接受前台的时间格式 传到后台的格式
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")//作用:后台的时间 格式化 发送到前台
private Date date;

@JsonFormat 默认是标准时区的时间, 北京时间 东八区 timezone=”GMT+8” 
作用:后台的时间 格式化 发送到前台

@DateTimeFormat 接受前台的时间格式 传到后台的格式

解决:springmvc中接收date数据问题的更多相关文章

  1. 解决SpringMvc后台接收json数据中文乱码问题

    原因分析 使用ajax从前台页面传输数据到后台controller控制器的时候,出现中文乱码 其实乱码问题出现的原因,就是由于默认的tomcat配置,接收请求是以ISO-8859-1来转码,导致中文出 ...

  2. 解决网页中Waiting (TTFB)数据加载过慢的问题

    解决网页中Waiting (TTFB)数据加载过慢的问题 最近做了一个网页,在本地测试良好,数据可以得到很快的反馈,但是当部署到云端Linux上时候,就会出现加载缓慢的问题.本地测试,得到数据大概3s ...

  3. springMVC中接收请求参数&&数据转发

    ### 1. 接收请求参数 #### 1.1. [不推荐] 通过HttpServletRequest获取请求参数 假设存在: <form action="handle_login.do ...

  4. 【Spring】SpringMVC中浅析Date类型数据的传递

    在控制器中加入如下代码: @InitBinder public void initBinder(ServletRequestDataBinder bin){ SimpleDateFormat sdf ...

  5. 解决springmvc中文件下载功能中使用javax.servlet.ServletOutputStream out = response.getOutputStream();后运行出异常但结果正确的问题

    问题描述: 在springmvc中实现文件下载功能一般都会使用javax.servlet.ServletOutputStream out = response.getOutputStream();封装 ...

  6. 解决Ubuntu中phpmyadmin对数据上传上限2M

    本文部分参考自:http://www.myhack58.com/Article/sort099/sort0102/2011/29396.htm 原文有少量错误或者过时的(相对于ubuntu15来说)内 ...

  7. 解决spark中遇到的数据倾斜问题

    一. 数据倾斜的现象 多数task执行速度较快,少数task执行时间非常长,或者等待很长时间后提示你内存不足,执行失败. 二. 数据倾斜的原因 常见于各种shuffle操作,例如reduceByKey ...

  8. 如何解决wamp中数据库读取数据是???的情况?

    数据库中数据正常,但是从数据库读取出的数据在网页中显示时是???,该怎么办呢? 左键点击托盘区的WampServer图标,选择Mysql--my.ini,就会打开配置文件 1.在[client]段落增 ...

  9. 解决js中post提交数据并且跳转到指定页面的问题总结

    今天在开发中过程中遇到了这个问题,js中利用JQuery中的 $.post("url", id, function(){}); 这个方法是数据提交正常,但是后台处理完成之后跳转无法 ...

随机推荐

  1. mybatis源码解析10---StatementHandler解析

    StatementHandler解析 接口的作用是statement处理器,位于mybatis包的org.apache.ibatis.executor.statement目录下,源码如下: packa ...

  2. webService入门理解

    最近可能开始要搞关于远程接口调用的玩意儿,所以上网查了一些关于远程调用额东西,其中有很多写得很不错,我把其中的比较好的几个整理一下,整理到一块儿,变成个人的理解写出来. 关于所谓的webService ...

  3. Bluetooth协议栈学习之SDP

    服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征.SDP定义了bluetooth client发现可用b ...

  4. 51Nod 1212 无向图最小生成树 (路径压缩)

    N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树.   Input 第1行:2个数N,M中间用空格分隔,N为点的数量,M为边的数量.(2 <= N <= 1000, 1 &l ...

  5. Linux下解析域名命令-dig 命令使用详解

    Linux下解析域名除了使用nslookup之外,开可以使用dig命令来解析域名,dig命令可以得到更多的域名信息.dig 命令主要用来从 DNS 域名服务器查询主机地址信息.dig的全称是 (dom ...

  6. 初学delphi

    今天女朋友的一门课,要求用delphi 软件编程,内容是一个计算器.当然,这个工作肯定是落在我的头上了. 这个软件是我第一次使用,边自学边进行代码编写,在n多次修改完善之后,终于成形.功能不是很多,跟 ...

  7. Linux 配置 JDK

    1. 上传 JDK 2. 解压文件 tar -xvf 文件名 3. 配置环境变量: 指令 vim /etc/profile 以上格式是不变的,使用时只改变 JAVA_HOME 和 JAVA_BIN 的 ...

  8. TF-IDF基本原理

    1.TF-IDF介绍 TF/IDF(term frequency–inverse document frequency)用以评估字词 对于一个文件集其中一份文件的重要程度.字词的重要性随着它在文件中出 ...

  9. MyEclipse项目的jquery.js发生[Multiple markers at this line - Missing semicolon]的解决方案

    问题描述: 导入jquery库后,发现提示错误信息:Multiple markers at this line - Missing semicolon,如下截图所示: 解决方案: 选中该jquery. ...

  10. 【题解】Luogu P1503 鬼子进村

    平衡树好题 原题传送门 这道题要用Splay,我博客里有对Splay的详细介绍 这道题思维有点难,要把被摧毁的节点插入平衡树,而不是把没有摧毁的节点插入 先把0和n+1插入平衡树,作为边界 操作1:摧 ...