1.局部日期转换

@Controller
public class ProductController{
@RequestMapping(value="/test/springmvc.do")
public String test(String name,Date birthday){
System.out.println(name+birthday);
return "";
}
//局部性的转换
@InitBinder
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.全局性的时间转换

1).在springmvc.xml添加配置

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<!-- 日期格式转换 -->
<property name="webBindingInitializer">
<bean class="cn.itcast.core.web.DateConverter" />
</property>
</bean>

2).编写 DateConverter

public class DateConverter implements WebBindingInitializer {    

    public void initBinder(WebDataBinder binder, WebRequest request) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat,true));
}
}

Springmvc配置时间日期转换的更多相关文章

  1. 时间日期转换工具类,获取当前时间YYYYMMDD24HHMISS、YYYYMMDDHHMISS

    YYYYMMDD24HHMISS:24小时制时间(显示上只是比YYYYMMDDHHMISS中间多了一个24),例:2018102224112440 YYYYMMDDHHMISS:12小时制时间,例20 ...

  2. SpringMVC配置全局日期转换器,处理日期转换异常

    Spring 3.1.1使用Mvc配置全局日期转换器,处理日期转换异常链接地址: https://www.2cto.com/kf/201308/236837.html spring3.0配置日期转换可 ...

  3. 【MySQL笔记】字符串、时间日期转换

    1.新增一列,将字符串日期(年.月.日)转换为Date类型   报错:Error Code: 1175. You are using safe update:http://jingyan.baidu. ...

  4. 02基于注解开发SpringMVC项目(jar包,异步,request,参数传递,多选的接收,Model传参,map传参,model传参,ajax,重定向,时间日期转换)

     1 所需jar包 项目结构如下: 2 web.xml配置文件的内容如下: <?xmlversion="1.0"encoding="UTF-8"?&g ...

  5. PHP phpexcel 导入时间/日期转换时间戳

    strtotime(gmdate('Y-m-d H:i',\PHPExcel_Shared_Date::ExcelToPHP($importtime))); /** * 判断字符串是否是日期格式 * ...

  6. springMVC 返回时间格式转换

    <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframewor ...

  7. python 使用time / datetime进行时间、时间戳、日期转换

    python 使用time 进行时间.时间戳.日期格式转换 #!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2017/11/7 15:53 # ...

  8. Java中时间日期格式化

    1.与日期时间相关的类:      第一:java.util.Date;                           将时间作为一个整体使用.处理时,使用Date类较为简便      第二:j ...

  9. 07、MySQL—时间日期类型

    时间日期类型 1.Date 日期类型:系统使用三个字节来存储数据,对应的格式为:YYYY-mm-dd,能表示的范围是从1000-01-01 到9999-12-12,初始值为0000-00-00 2.T ...

随机推荐

  1. 《算法》第四章部分程序 part 1

    ▶ 书中第四章部分程序,加上自己补充的代码,包含无向 / 有向图类 ● 无向图类 package package01; import java.util.NoSuchElementException; ...

  2. JUC 之 ThreadPoolExecutor 的一些研究

    ThreadPoolExecutor 概述:===================================================================== 构造函数: 4个 ...

  3. requestAnimFrame动画兼容性封装

    window.requestAnimFrame=function(){ return window.requestAnimationFrame ||window.webkitRequestAnimat ...

  4. leetcode153

    class Solution: def findMin(self, nums: 'List[int]') -> int: l = 0 h = len(nums)-1 while l < h ...

  5. 如何轻松干掉svd(矩阵奇异值分解),用代码说话

    svd我认识我机器学习里面最扯淡的玩意了.尼玛.老实说,好多机器学习的书老是在扯svd有多高端,然后看了netflix电影推荐大赛,哇塞,冠军队就是用svd+做的.然后狠狠的下载了所有他们的论文,硬是 ...

  6. NRF51822之使用外部32Mhz晶振

    硬件平台为微雪BLE400的(将原来的16mhz晶振改为32mhz.两个旁电容改为22pf) 以nRF51_SDK_10.0.0_dc26b5e\examples\ble_peripheral\ble ...

  7. 微信、陌陌等著名IM软件设计架构详解(转)

    对微信.陌陌等进行了分析,发出来分享一下(时间有些久了) 电量:对于移动设备最大的瓶颈就是电量了.因为用户不可能随时携带电源,充电宝.所以必须考虑到电量问题.那就要检查我们工程是不是有后台运行,心跳包 ...

  8. Pronunciation – The Definitive Guide to the Top 100 Words in American English

    Pronunciation – The Definitive Guide to the Top 100 Words in American English Share Tweet Share Tagg ...

  9. webpack 自动发现 entry 的配置和引用方式

    假定我们的项目目录为如下的样子: - root/ - assets/ - app/ - global.js - index/ - index.js - auth/ - login.js - regis ...

  10. [C语言]使用数组

    ----------------------------------------------------------------------------- // main.c 例 // Created ...