springmvc date


- ConversionService:只有数据转换功能;
- ConversionServiceFactoryBean:与ConversionService对应;
- FormattingConversionService:具有数据转换和数据格式化功能;
- FormattingConversionServiceFactoryBean:与FormattingConversionService对应;可以注册自定义的转换器,又可以注册自定义的注解驱动器逻辑。
2. 具体实现
步骤1:配置FormattingConversionServiceFactoryBean

<mvc:annotation-driven conversion-service="conversionService"/><bean id="conversionService"class="org.springframework.format.support.FormattingConversionServiceFactoryBean"><property name="converters"><list><!-- <bean class="com.ll.model.StringToPersonConverter" /> --></list></property></bean>
步骤2:使用@DateTimeFormat和@NumberFormat注解对象属性

步骤3:控制层

步骤4:前台请求



3. 简单介绍@DateTimeFormat与@NumberFormat



一、后台日期类型解析到前端
1.在springmvc的配置文件中添加这个.annotation-driven在配置文件中只配置一次 (此方法全局作用)
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
2.直接在字段上写上
@JsonFormat(pattern="yyyy-MM-dd",timezone="GMT-8")
private Date inputtime;
二、前端日期类型传到后台
1.在Controller类中添加这个方法 (此方法全局作用)
@InitBinder
public void initBinder(WebDataBinder binder){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
2.直接在字段上添加
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date beginDate;
第三种:https://blog.csdn.net/u012410733/article/details/72773095
springmvc date的更多相关文章
- springmvc Date类型转换
有时候我们会碰到这么一个问题,有一个实体类,里面有一个Date类型的数据,jsp页面传递的时间参数是String的,这就导致无法对应,springmvc无法帮我们自动封装参数到实体类中了,这里我解决的 ...
- SpringMvc date数据传递处理
1.form表单提交date数据 form表单提交的date数据要在接收的字段上加入@DateTimeFormat注解 @DateTimeFormat(pattern = "yyyy-MM- ...
- 【Spring】SpringMVC中浅析Date类型数据的传递
在控制器中加入如下代码: @InitBinder public void initBinder(ServletRequestDataBinder bin){ SimpleDateFormat sdf ...
- SpringMVC在传递date型数据时的配置
查阅了好多资料, 最后才发现原来只是添加一个方法就能解决的问题, 但是看了半天又没看明白, 只是知道这么写就能成功, 先记下来, 以后再研究吧, 在配置好springMVC的时候, 可以在前台的for ...
- SpringMVC处理Date类型的成员变量方法
原文链接:http://www.tuicool.com/articles/aYfaqa 在使用 SpringMVC 的时候,我们可能需要将一个对象从 View 传递给 Controller .而当这个 ...
- SpringMVC解决@ResponseBody返回Json的Date日期类型的转换问题
在做项目的时候,发现后台把Date类型的属性以json字符串的形式返回,前台拿不到转换后的日期格式,始终响应回去的都是long类型时间戳. 查阅资料之后找到解决方法: 方法一(在springmvc的x ...
- springMVC返回json数据时date类型数据被转成long类型
在项目的过程中肯定会遇到ajax请求,但是再用的过程中会发现,在数据库中好好的时间类型数据:2017-05-04 17:52:24 在转json的时候,得到的就不是时间格式了 而是145245121这 ...
- 解决:springmvc中接收date数据问题
这里提供三种解决方案. 一.局部转换 :只是对当前Controller类有效 springMVC.xml中添加: <bean class="org.springframework.we ...
- SpringMVC 处理Date类型数据@InitBinder @DateTimeFormat 注解 的使用
使用SpringMVC的时候,需要将表单中的日期字符串转换成对应JavaBean的Date类型,而SpringMVC默认不支持这个格式的转换,解决方法有两种,如下: 方法一 . 在需要日期转换的Con ...
随机推荐
- [OPENCV]cvHoughLines2使用说明
1.cvHoughLines2函数定义: CvSeq *cvHoughLines2 { CvArr *image, void *line_storage, int method, double rho ...
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习4
#include <iostream>#include <string>using namespace std;int main(){ string fname; string ...
- PhantomJS、CasperJS安装配置图文详解
目前网站主流的加载方式: 一种是同步加载:另一种是异步加载,也即我们常说的用ajax.对于同步加载的网站,普通的爬虫程序轻松就能搞定.但是对于那种异步请求数据的网站,通常使用selenium+Phan ...
- 让公式在网页传播——mathJAX
让公式在网页传播--mathJAX 对于学生党而言,写公式最好的工具是LaTeX,但LaTeX把公式展示到互联网上就有些困难,而使用截图又不太雅观.幸运的是,mathJAX引擎可以在浏览器中解析渲染数 ...
- Git_git diff 与 git diff -- cached 区别
1.首先,打开一个干净的工作区 2.对文件进行修改 3.使用 git diff 进行查看(这里的解释可能不是很准确,暂时这么理解!) 4. 执行 git add 将工作区中的内容add到stage, ...
- pygame-KidsCanCode系列jumpy-part0-使用sprite
油管(youtube)上有一个号称"史上最好的pygame教程"(传送门:https://www.youtube.com/watch?v=VO8rTszcW4s&list= ...
- 从注册表清理 IE10,IE11 用户代理字符串(UserAgent)中的垃圾信息
某一天,我发现我的 IE User Agent 字符串里面竟然含有刷机大师.百度浏览器等许多垃圾,国货流氓见怪不怪了. 微软自家的.NET CLR也占据了一大片,看着也不爽. 决定清理一下,但是却没找 ...
- Ubuntu 18.04 安装Virtual Box or VMWare workstation Pro 14
Linux相关的知识:https://www.cnblogs.com/dunitian/p/4822808.html#linux Virtual Box:sudo apt-get install vi ...
- .Net转Java.01.从Main(main)函数说起
在C#中,main函数的签名可以有四种 static void Main(string[] args)static void Main()static int Main(string[] args)s ...
- Cocos Creator脚本开发事例
HelloWorld.js window.Global = { gint: 168, }; cc.Class({ extends: cc.Component, properties: { label: ...