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. python ftp文件夹文件递归上传推送

  2. java 获得系统当前时间

    import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.uti ...

  3. python学习笔记_week14

    Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. s1 import socket def handle_reques ...

  4. 11.vim编辑器命令

    VI中的多行删除与复制   方法一: 单行删除,:1(待删除行)d 多行删除 ,:1,10d   方法二: 光标所在行,dd 光标所在行以下的N行,Ndd   方法1: 光标放到第6行, 输入:2yy ...

  5. android stuido的代码排版的快捷建CTRL+ALT+L

    CTRL+ALT+L 需要主要留意的地方是QQ的与其冲突的 我将qq的中快捷方式给去除

  6. Installing PHP5 on Ubuntu Server

    When installing PHP 5 from source I ran into the following problems and solutions: Problem:configure ...

  7. linux集群时间同步搭建

    http://xstarcd.github.io/wiki/sysadmin/ntpd.html http://www.voidcn.com/blog/xuxudede1989/article/p-4 ...

  8. html:块级元素和行内元素的特点

    display:block: 块元素会独自占据一整行,或者多行,可以任意设置其大小尺寸,是用于搭建网页布局的必须部分,使网页结构更加紧凑合理. 块级元素width.height.padding.mar ...

  9. JSP基本_EL式

    1.EL式下記二種類がある.① ${式} : JSPの出力(レンダリング)時に評価 (JSP2.0から)② #{式} : タグハンドラにより任意のタイミングで評価 (JSP2.1から) 2.オブジェク ...

  10. Delphi中TApplication详解(转仅供自己参考)

    转自:http://blog.sina.com.cn/s/blog_4d6f55d90100bmv9.html TApplication是用于Delphi应用程序的类型,该类在单元forms中声明.T ...