SpringBoot2 时间类型自动格式化 自动转换

package com.archibladwitwicke.springboot2.chapter03.configurer; import com.archibladwitwicke.springboot2.chapter03.intercept.AdminLoginIntercept;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {
/**
* 自动转换时间格式
*
* @param registry date
*/
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
}
}
package com.archibladwitwicke.springboot2.chapter03.controller; import com.archibladwitwicke.springboot2.chapter03.pojo.UserAndDate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; @Controller
@RequestMapping("/dateconvert")
public class TestDateConvertController { @RequestMapping("/dc")
@ResponseBody
public String say(UserAndDate user) {
return "is ok";
}
}
package com.archibladwitwicke.springboot2.chapter03.pojo;
import java.util.Date;
public class UserAndDate {
private String name;
private String age;
private Date birthday;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}

SpringBoot2 时间类型自动格式化 自动转换的更多相关文章
- EL表达式获取日期时间类型后格式化的问题
最近在项目中遇到的问题,就是从后台取到的java.util.Date类型的数据,在前台需要格式化的问题. 开始想了很多办法,其实在JSP页面中处理很简单,JSTL提供的format标签即可解决这个问题 ...
- @InitBinder 前端传递date时间类型属性时,转换错误问题
在Controller里加上这段代码 @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomE ...
- 表单中的日期 字符串和Javabean中的日期类型的属性自动转换
搞了一上午的bug最终还是因为自己springMVC的注解不熟悉的原因,特记录. 在实际操作中经常会碰到表单中的日期 字符串和Javabean中的日期类型的属性自动转换, 而springMVC默认不支 ...
- springMVC注解@initbinder日期类型的属性自动转换
在实际操作中经常会碰到表单中的日期 字符串和Javabean中的日期类型的属性自动转换, 而springMVC默认不支持这个格式的转换,所以必须要手动配置, 自定义数据类型的绑定才能实现这个功能. 一 ...
- mysql 日期时间类型 自动转型 及 运算
日期时间类型自动转型 -- now().字符串.数字转datetime类型 create table t(dt datetime);insert into t values(now());insert ...
- @JsonFormat 日期格式自动格式化
通常日期格式都是以时间戳的形式存放在数据库里,当前端页面通过接口查询时,我们会将一个对象的某些属性查出来返回给页面. 例如,某个类里面有个属性 Timestamp create_time 给这个对象实 ...
- 在javaScript中把非数值类型的数据自动转换为数值类型的两种方式
一.使用Number()函数. 二.使用parseInt()/parseFloat()函数. 详情: 一.使用Number()函数将非数值类型的数据自动的转化为数组类型 Number()函数可以将任何 ...
- vsCode 设置vue 保存自动格式化代码
setting { // vscode默认启用了根据文件类型自动设置tabsize的选项 "editor.detectIndentation": false, // 重新设定tab ...
- C++中各种时间类型的转换(包括MFC中的时间类型)
平时写代码会经常遇到时间类型转换的问题,如时间戳转为格式化时间,或者反过来等,时间类型有的为time_t,还有FILETIME一堆,在这里记录下他们之间是如何转换的. 时间类型及其意义 FILETIM ...
随机推荐
- 译: 2. Apache Axis2安装指南
Apache Axis2安装指南 本文档提供有关Axis2分发包,系统先决条件以及设置环境变量和工具的信息,然后提供有关安装方法的详细说明. 请将您的反馈发送至:java-dev@axis.apach ...
- 【Unity】第6章 Unity脚本开发基础
分类:Unity.C#.VS2015 创建日期:2016-04-16 一.简介 游戏吸引人的地方在于它的可交互性.如果游戏没有交互,场景做得再美观和精致,也难以称其为游戏. 在Unity中,游戏交互通 ...
- How do I learn mathematics for machine learning?
https://www.quora.com/How-do-I-learn-mathematics-for-machine-learning How do I learn mathematics f ...
- EF事务处理封装公用
/// <summary> /// EF事务封装 公用类 /// </summary> public class TransactionCommon { DbContextTr ...
- update set where exists 多表更新 在mssql、MySQL、Oracle中分别用法
MySQL: UPDATE ChgCfm t1 INNER JOIN tb_dz_file t2 ON t1.ID = t2.ID ' SQLserver: FROM ChgCfmRcd t1 ' F ...
- iOS开发-按钮的基本使用
// // ViewController.m // 05-用代码创建按钮 // // Created by vic fan on 2017/7/30. // Copyright © 2017年 ...
- 【转帖】(一)unity4.6Ugui中文教程文档-------概要
原帖至上,移步请戳:(一)unity4.6Ugui中文教程文档-------概要 unity4.6中的一个重要的升级就是GUI ,也把它称为UGUI ,废话我不多说,大家可以百度了解一下. 虽然现在处 ...
- Java获取某个月的天数
https://blog.csdn.net/wtopps/article/details/48262221 ********************************************** ...
- JS 实现日期信息增加年数,月数,天数
function DateAdd(interval, number, date) { /* * 功能:实现JSScript的DateAdd功能. * 参数:interval,字符串表达式,表示要添加的 ...
- 【转载】关于Java String, StringBuilder, StringBuffer, Hashtable, HashMap的面试题
REF: http://blog.csdn.net/fightforyourdream/article/details/15333405 题目是一道简单的小程序,像下面这样:[java] view p ...