springmvc的日期类型转换

# spring mvc绑定参数之类型转换有三种方式:

## 1.实体类中加日期格式化注解

@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
private Date creationTime;

## 2.属性编辑器

spring3.1之前

在Controller类中通过@InitBinder完成

/**
* 在controller层中加入一段数据绑定代码
* @param webDataBinder
*/
@InitBinder
public void initBinder(WebDataBinder webDataBinder) throws Exception{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
simpleDateFormat.setLenient(false);
webDataBinder.registerCustomEditor(Date.class , new CustomDateEditor(simpleDateFormat , true));
}
备注:自定义类型转换器必须实现PropertyEditor接口或者继承PropertyEditorSupport类
写一个类 extends propertyEditorSupport(implements PropertyEditor){
public void setAsText(String text){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy -MM-dd hh:mm");
Date date = simpleDateFormat.parse(text);
this.setValue(date);
}
public String getAsTest(){
Date date = (Date)this.getValue();
return this.dateFormat.format(date);
}
}

## 3. 类型转换器Converter

全局类型转换

2019-03-2519:52:18

springmvc的日期类型转换的更多相关文章

  1. [转]SpringMVC日期类型转换问题三大处理方法归纳

    http://blog.csdn.net/chenleixing/article/details/45190371 前言 我们在SpringMVC开发中,可能遇到比较多的问题就是前台与后台实体类之间日 ...

  2. SpringMVC日期类型转换问题三大处理方法归纳

    方法一:实体类中加日期格式化注解 @DateTimeFormat(pattern = "yyyy-MM-dd") private Date receiveAppTime; 方法二: ...

  3. SpringMVC日期类型转换问题处理方法归纳

    前言 我们在SpringMVC开发中,可能遇到比较多的问题就是前台与后 台实体类之间日期转换处理的问题了,说问题也不大,但很多人开发中经常会遇到这个问题,有时很令人头疼,有时间问题暴露的不是很明显,然 ...

  4. SpringMVC 06: 日期类型的变量的注入和显示

    日期处理和日期显示 日期处理 此时SpringMVC的项目配置和SpringMVC博客集中(指SpringMVC 02)配置相同 日期处理分为单个日期处理和类中全局日期处理 单个日期处理: 使用@Da ...

  5. springMVC 前后台日期格式传值解决方式之二(共二) @InitBinder的使用

    关于springmvc日期问题的解决方式 除了本博客的[springMVC 前后台日期格式传值解决方式之 @DateTimeFormat的使用和配置]一文, 还有如下这种方式: 在Controller ...

  6. struts2 jsp提交日期类型转换及国际化实现

    概述:下面通过jsp提交输入注册信息信息,同时完成过程文件国家化问题演示说明.[注册日期转换用注解方式实现] 工程截图: 注册页面jsp文件: <%@ page language="j ...

  7. springMvc接受日期类型参数处理

    这个问题,也即是springMvc如何进行参数类型的转换 以把client传过来一个String类型,转换为日期类型为例: 1.controller /** * 接收日期类型参数 * 注意: * sp ...

  8. springmvc(3)--数据类型转换

    springmvc 配置 中conversionService可以配置类型转换,springmvc 参数绑定 中各种绑定方式和注解就是使用的这些转换器 一.先看下spring提供的内建类型转换器 第一 ...

  9. Springmvc 进行数据类型转换

    SpringMVC进行一些常用的数据类型转换,这里以Date 数据类型的转换为例. SpringMVC表单中输入日期,一般都是以字符串的形式输入,如何将字符形式的日期转换为Date 类型的呢?这里只需 ...

随机推荐

  1. expect 批量自动部署ssh 免密登陆

    [root@node2 ssh]# cat auto_ssh.sh #!/usr/bin/expect -f ########################################## #通 ...

  2. 3种自增ID说明

    自增ID 1.@@identity 所有会话所有表最后一个自增ID 2.IDENT_CURRENT('表名') 所有会话当前表的自增ID 3.SCOPE_IDENTITY() 当前会话所有表最后一个自 ...

  3. 微信小程序开发学习(二)

    一些官方API 总结了一些官方API,便于之后有用时针对性查找(发现官方给了好多好用的API)官方API文档 基础 wx.canIUse:判断小程序的API,回调,参数,组件等是否在当前版本可用,返回 ...

  4. 【Python】Flask中@wraps的使用

    先说总结,白话来讲,@wraps相当于是装饰器的装饰器. python内置的方法使用解释,看起很复杂的样子┓( ´∀` )┏ def wraps(wrapped, assigned = WRAPPER ...

  5. juypter4.4.0 自动补全

    python -m pip install jupyter_contrib_nbextensions jupyter contrib nbextension install --user --skip ...

  6. RROR: [XSIM 43-3238] Failed to link the design.

    仿真时遇到上述错误,在tcl下运行 set_property -name {xsim.elaborate.xelab.more_options} -value {-cc clang} -objects ...

  7. SQLAlchemy使用介绍

    SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers ...

  8. Convolutional Neural Network in TensorFlow

    翻译自Build a Convolutional Neural Network using Estimators TensorFlow的layer模块提供了一个轻松构建神经网络的高端API,它提供了创 ...

  9. RabbitMQ一个简单可靠的方案(.Net Core实现)

    前言 最近需要使用到消息队列相关技术,于是重新接触RabbitMQ.其中遇到了不少可靠性方面的问题,归纳了一下,大概有以下几种: 1. 临时异常,如数据库网络闪断.http请求临时失效等: 2. 时序 ...

  10. 简单使用WebSocket实现聊天室

    环境需求:flask,websocket第三方包 目录结构 web中实现群聊 ws_群聊.py文件 # 实现一个websocket 先下载包 gevent-websocket from flask i ...