SpringMVC日期类型转换问题三大处理方法归纳
方法一:实体类中加日期格式化注解
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date receiveAppTime;
方法二:控制器Action中加入一段数据绑定代码
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); //true:允许输入空值,false:不能为空值
}
方法三:实现一个全局日期类型转换器并进行配置
此方法较为复杂,请详细查看本人的这篇博文:SpringMVC配置全局日期转换器,处理日期转换异常
附加方法四:适合页面把日期类型转换成字符串且JSP,Freemark页面
JSP模版引擎方法:
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<fmt:formatDate value="${job.jobtime }" pattern="yyyy-MM-dd HH:mm:ss"/>
Freemarker模版引擎方法
<input id="receiveAppTime" name="receiveAppTime" type="text" value="${(bean.receiveAppTime?string('yyyy-MM-dd'))!}" />
SpringMVC日期类型转换问题三大处理方法归纳的更多相关文章
- [转]SpringMVC日期类型转换问题三大处理方法归纳
http://blog.csdn.net/chenleixing/article/details/45190371 前言 我们在SpringMVC开发中,可能遇到比较多的问题就是前台与后台实体类之间日 ...
- SpringMVC日期类型转换问题处理方法归纳
前言 我们在SpringMVC开发中,可能遇到比较多的问题就是前台与后 台实体类之间日期转换处理的问题了,说问题也不大,但很多人开发中经常会遇到这个问题,有时很令人头疼,有时间问题暴露的不是很明显,然 ...
- springmvc的日期类型转换
springmvc的日期类型转换 # spring mvc绑定参数之类型转换有三种方式: ## 1.实体类中加日期格式化注解 @DateTimeFormat(pattern="yyyy- ...
- springmvc的类型转换
一.springmvc的类型转换 (一)默认情况下,springmvc内置的类型转换器只能 将"yyyy/MM/dd"类型的字符串转换为Date类型的日期 情境一: 而现在我们无 ...
- SpringMVC日期类型接收空值异常问题
最近遇到SpringMVC写个controller类,传一个空串的字符类型过来,正常情况是会自动转成date类型的,因为数据表对应类类型就是date的 解决方法是在controller类的后面加个注解 ...
- spring参数类型异常输出(二), SpringMvc参数类型转换错误输出(二)
spring参数类型异常输出(二), SpringMvc参数类型转换错误输出(二) >>>>>>>>>>>>>>&g ...
- spring参数类型异常输出,SpringMvc参数类型转换错误输出
spring参数类型异常输出, SpringMvc参数类型转换错误输出 >>>>>>>>>>>>>>>> ...
- 转:SpringMVC之类型转换Converter(GenericConverter)
转: http://blog.csdn.net/fsp88927/article/details/37692215 SpringMVC 之类型转换 Converter 1.1 目录 1.1 目录 1. ...
- SpringMVC 之类型转换Converter详解转载
SpringMVC之类型转换Converter详解 本文转载 http://www.tuicool.com/articles/uUjaum 1.1 目录 1.1 目录 1.2 ...
随机推荐
- Implement custom foreach function in C#
http://msdn.microsoft.com/en-us/library/System.Collections.IEnumerator.aspx http://support.microsoft ...
- 11个实用但你可能不知道的Python程序库
目前,网上已有成千上万个Python包,但几乎没有人能够全部知道它们.单单PyPi上就有超过47000个包列表. 现在,越来越多的数据科学家开始使用Python,虽然他们从pandas,scikit- ...
- android 基础学习图片六progross
加载进度条应用
- Java安全机制之泛型(JDK1.5)
泛型,类型安全机制. 好处: 1.将运行时期出现问题ClassCastException转移到了编译时期,方便解决问题,减少运行时期的问题,有利于程序的健壮性. 2.避免了强制转换的麻烦 泛型格式: ...
- Nginx 之一:编译安装nginx 1.8.1 及配置
一:基介绍 官网地址www.nginx.org,nginx是由1994年毕业于俄罗斯国立莫斯科鲍曼科技大学的同学为俄罗斯rambler.ru公司开发的,开发工作最早从2002年开始,第一次公开发布时间 ...
- javascript定义函数不同方式的区别
学习javascript中遇到了这么一个问题,代码如下: var test = 'a'; function test() { alert('Hello World!'); } alert(test); ...
- Vmware虚拟机网络模式及虚拟机与物理机通信方法
[转]http://www.cqeis.com/news_detail/newsId=1477.html Vmware虚拟机软件是一个“虚拟PC”软件,它使你可以在一台机器上同时运行二个或更多Wind ...
- select_related
作用:减少DB访问次数 from django.db import models class Blog(models.Model): name = models.CharField(max_lengt ...
- 转: 用css把图片转为灰色图
小tip: 使用CSS将图片转换成黑白(灰色.置灰) by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.co ...
- Nginx Rewrite规则初探(转)
Nginx rewrite(nginx url地址重写)Rewrite 主要的功能就是实现URL的重写,Nginx的Rewrite规则采用Pcre,perl兼容正则表达式的语法规则匹配,如果需要Ng ...