
1package com.archibladwitwicke.springboot2.chapter03.configurer;
2
3import com.archibladwitwicke.springboot2.chapter03.intercept.AdminLoginIntercept;
4import org.springframework.context.annotation.Configuration;
5import org.springframework.format.FormatterRegistry;
6import org.springframework.format.datetime.DateFormatter;
7import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
8import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
9
10@Configuration
11public class MyWebMvcConfigurer implements WebMvcConfigurer {
12 1516
17 @Override
18 public void addFormatters(FormatterRegistry registry) {
19 registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
20 }
21}
22
23package com.archibladwitwicke.springboot2.chapter03.controller;
24
25import com.archibladwitwicke.springboot2.chapter03.pojo.UserAndDate;
26import org.springframework.stereotype.Controller;
27import org.springframework.web.bind.annotation.RequestMapping;
28import org.springframework.web.bind.annotation.ResponseBody;
29
30@Controller
31@RequestMapping("/dateconvert")
32public class TestDateConvertController {
33
34 @RequestMapping("/dc")
35 @ResponseBody
36 public String say(UserAndDate user) {
37 return "is ok";
38 }
39}
40
41package com.archibladwitwicke.springboot2.chapter03.pojo;
42
43import java.util.Date;
44
45public class UserAndDate {
46 private String name;
47 private String age;
48 private Date birthday;
49
50 public String getName() {
51 return name;
52 }
53
54 public void setName(String name) {
55 this.name = name;
56 }
57
58 public String getAge() {
59 return age;
60 }
61
62 public void setAge(String age) {
63 this.age = age;
64 }
65
66 public Date getBirthday() {
67 return birthday;
68 }
69
70 public void setBirthday(Date birthday) {
71 this.birthday = birthday;
72 }
73}
