Springmvc配置时间日期转换
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配置时间日期转换的更多相关文章
- 时间日期转换工具类,获取当前时间YYYYMMDD24HHMISS、YYYYMMDDHHMISS
YYYYMMDD24HHMISS:24小时制时间(显示上只是比YYYYMMDDHHMISS中间多了一个24),例:2018102224112440 YYYYMMDDHHMISS:12小时制时间,例20 ...
- SpringMVC配置全局日期转换器,处理日期转换异常
Spring 3.1.1使用Mvc配置全局日期转换器,处理日期转换异常链接地址: https://www.2cto.com/kf/201308/236837.html spring3.0配置日期转换可 ...
- 【MySQL笔记】字符串、时间日期转换
1.新增一列,将字符串日期(年.月.日)转换为Date类型 报错:Error Code: 1175. You are using safe update:http://jingyan.baidu. ...
- 02基于注解开发SpringMVC项目(jar包,异步,request,参数传递,多选的接收,Model传参,map传参,model传参,ajax,重定向,时间日期转换)
1 所需jar包 项目结构如下: 2 web.xml配置文件的内容如下: <?xmlversion="1.0"encoding="UTF-8"?&g ...
- PHP phpexcel 导入时间/日期转换时间戳
strtotime(gmdate('Y-m-d H:i',\PHPExcel_Shared_Date::ExcelToPHP($importtime))); /** * 判断字符串是否是日期格式 * ...
- springMVC 返回时间格式转换
<mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframewor ...
- python 使用time / datetime进行时间、时间戳、日期转换
python 使用time 进行时间.时间戳.日期格式转换 #!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2017/11/7 15:53 # ...
- Java中时间日期格式化
1.与日期时间相关的类: 第一:java.util.Date; 将时间作为一个整体使用.处理时,使用Date类较为简便 第二:j ...
- 07、MySQL—时间日期类型
时间日期类型 1.Date 日期类型:系统使用三个字节来存储数据,对应的格式为:YYYY-mm-dd,能表示的范围是从1000-01-01 到9999-12-12,初始值为0000-00-00 2.T ...
随机推荐
- try or install Ubuntu on MeegoPad T01
Ref: Install Ubuntu on Meego Pad T01 with a Live ISO Image MeegoPad T01 has recently been shown to b ...
- mysql大纲
一.概述 1.1 关系型数据.非关系型数据.半关系型数据 1.2 关系型数据库和非关系型数据库 1.3 发展史 二.MySQL组件和安装 三.数据库语言和主要概念 3.1 数据库语言 DML.DDL. ...
- SPARK快学大数据分析概要
Spark 是一个用来实现快速而通用的集群计算的平台.在速度方面,Spark 扩展了广泛使用的MapReduce 计算模型,而且高效地支持更多计算模式,包括交互式查询和流处理.在处理大规模数据集时,速 ...
- Analysis of Web.xml in Hello1project
一下是hello1 web inf 里的 web.xml <?xml version="1.0" encoding="UTF-8"?><w ...
- idea 安装三方插件的方法
<一>在线安装 1,File -> Setting -> Plugins, 大红框内是已经安装的插件,可以搜索 2, 点击上图小红框内的按钮, 如下,搜索自己想要的插件,选中, ...
- day04-完整性约束
完整性约束 关键字: not null 与 default unique primary auto_increment foreign key 1.介绍 约束条件与数据类型的宽度一样,都是可选参数作用 ...
- centos7 操作记录
centos7 firewall 命令查看已经开放的端口firewall-cmd --list-ports查看开放的服务firewall-cmd --list-services开启端口firewall ...
- UI5-学习篇-13-Eclipse 开发UI5应用
1.Eclipse环境配置及组件安装 UI5-学习篇-1-Eclipse开发工具及环境搭建 2.创建项目 3.设置代理映射 打开WebContent->WEB-INF->web.xml文件 ...
- java定时任务——间隔指定时间执行方法
摘要:运行 main 方法的时候开始进行定时任务, service.scheduleAtFixedTate(task,5,TimeUnit.SECONDS);方法为关键 此次任务就是 run() 方法 ...
- svn从本地更新了资源库的资源后删除了某个文件夹无法恢复(已解决)
事件描述: 删除了本地svn的某个文件夹中的某个文件后,想要恢复,但是无法恢复,解决方法如下 步骤: 1:在删除的文件夹下右键,选择TortoiseSVN——>Revert... 2:选择需要恢 ...