SpringBoot复习(30):@DateTimeFormat注解的使用

一、实体类

复制代码
package cn.edu.tju.domain;

import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

public class Person {
    private int age;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
}

二、控制器类:

复制代码
package cn.edu.tju.controller;


import cn.edu.tju.domain.Person;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
public class DateController {

    @PostMapping("/getDate")
    public String getInfo(@RequestBody Person person){
        return new Date().toLocaleString();
    }

    @PostMapping("/getDate2")
    public String getInfo2(@ModelAttribute Person person){
        return new Date().toLocaleString();
    }
}
相关推荐
96775 分钟前
springMVC请求处理全过程
java
gelald7 分钟前
Spring - 事务管理
java·后端·spring
nghxni7 分钟前
LightESB Timer发布:服务级日志与响应编码增强
后端
橘子编程8 分钟前
编译原理:从理论到实战全解析
java·linux·python·ubuntu
xuhaoyu_cpp_java8 分钟前
Maven学习(一)
java·经验分享·笔记·学习·maven
Southern Wind9 分钟前
AI Skill Server 动态技能中台
前端·后端·mysql·node.js
sibylyue9 分钟前
Nginx\Tomcat\Jetty\Netty
java·nginx·http
于先生吖10 分钟前
基于 SpringBoot 架构,高性能 JAVA 动漫短剧系统源码
java·开发语言·spring boot
chen_ever13 分钟前
从网络基础到吃透 Linux 高并发 I/O 核心(epoll+零拷贝 完整版)
linux·网络·c++·后端
斌味代码17 分钟前
SpringBoot 3 实战:虚拟线程、全局异常处理与 JWT 鉴权完整方案
java·spring boot·后端