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 时间类型自动格式化 自动转换的更多相关文章

  1. EL表达式获取日期时间类型后格式化的问题

    最近在项目中遇到的问题,就是从后台取到的java.util.Date类型的数据,在前台需要格式化的问题. 开始想了很多办法,其实在JSP页面中处理很简单,JSTL提供的format标签即可解决这个问题 ...

  2. @InitBinder 前端传递date时间类型属性时,转换错误问题

    在Controller里加上这段代码 @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomE ...

  3. 表单中的日期 字符串和Javabean中的日期类型的属性自动转换

    搞了一上午的bug最终还是因为自己springMVC的注解不熟悉的原因,特记录. 在实际操作中经常会碰到表单中的日期 字符串和Javabean中的日期类型的属性自动转换, 而springMVC默认不支 ...

  4. springMVC注解@initbinder日期类型的属性自动转换

    在实际操作中经常会碰到表单中的日期 字符串和Javabean中的日期类型的属性自动转换, 而springMVC默认不支持这个格式的转换,所以必须要手动配置, 自定义数据类型的绑定才能实现这个功能. 一 ...

  5. mysql 日期时间类型 自动转型 及 运算

    日期时间类型自动转型 -- now().字符串.数字转datetime类型 create table t(dt datetime);insert into t values(now());insert ...

  6. @JsonFormat 日期格式自动格式化

    通常日期格式都是以时间戳的形式存放在数据库里,当前端页面通过接口查询时,我们会将一个对象的某些属性查出来返回给页面. 例如,某个类里面有个属性 Timestamp create_time 给这个对象实 ...

  7. 在javaScript中把非数值类型的数据自动转换为数值类型的两种方式

    一.使用Number()函数. 二.使用parseInt()/parseFloat()函数. 详情: 一.使用Number()函数将非数值类型的数据自动的转化为数组类型 Number()函数可以将任何 ...

  8. vsCode 设置vue 保存自动格式化代码

    setting { // vscode默认启用了根据文件类型自动设置tabsize的选项 "editor.detectIndentation": false, // 重新设定tab ...

  9. C++中各种时间类型的转换(包括MFC中的时间类型)

    平时写代码会经常遇到时间类型转换的问题,如时间戳转为格式化时间,或者反过来等,时间类型有的为time_t,还有FILETIME一堆,在这里记录下他们之间是如何转换的. 时间类型及其意义 FILETIM ...

随机推荐

  1. debian linux 下设置开机自启动

    懒得写了,一张图简单明了.其实很简单,一开始没有加上nohup有点问题.现在问题已解决.

  2. 查询系统负载信息 Linux 命令详解

    linux uptime命令主要用于获取主机运行时间和查询linux系统负载等信息.uptime命令过去只显示系统运行多久.现在,可以显示系统已经运行了多长 时间,信息显示依次为:现在时间.系统已经运 ...

  3. (转载)220v交流接触器自锁接线图另接热继电器

    220v交流接触器自锁接线图另接热继电器 时间:2015-06-26 20:36:56编辑:电工栏目:接触器 导读:求一个220v交流接触器自锁接线图,外加个热继电器怎么接,接线图中两根粉色的线接的就 ...

  4. ie6遮罩层兼容 100%高度的实现

    .black { position:absolute;width:100%;height:100%;opacity:0.5;filter:alpha(opacity=50);background:#0 ...

  5. delphi 学习笔记的例子

    由于360改变了共享策略,导致之前的共享连接不能使用 重新共享了下. http://yunpan.cn/cgS2DBRT572jy (提取码:1eda)

  6. 序列化ADODataSet, ADOQuery

    经过昨天晚上一折腾把做了一个DIOCP直接传递TADOQuery的Demo,在google上找了一系列的资料. 这样服务端可以直接将TADOQuery查询出来的数据直接转换成TStream自己进行传递 ...

  7. Asp.Net MVC App_Code无法识别

    Asp.Net MVC需要写公共类的时候 右击添加 App_Code 文件夹,新建类—>右击类—>属性,生成操作 —>选择 —>编译 Asp.Net MVC项目本身是个应用程序 ...

  8. PostgreSQL建表SQL语句写法

    DROP TABLE IF EXISTS bus; CREATE TABLE bus( id SERIAL PRIMARY KEY, mac ) NOT NULL UNIQUE, route int ...

  9. 【Python】解决UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 0: ordinal not in range(128)

    指定文件字符集为utf-8 在文件头部加入以下代码: import sys reload(sys) sys.setdefaultencoding('utf-8')

  10. Python(四)之Python流程控制(if、while、for)

    Python流程控制 if测试: if 条件测试表达式: 组合条件测试: x and y:与运算 x or y:或运算 not x:非运算 while: break:跳出最内层的循环 continue ...