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();
    }
}
相关推荐
心运软件17 分钟前
SpringBoot+ Vue校园社团管理平台的完整架构设计
vue.js·后端
真上帝的左手40 分钟前
10. 软件设计&架构-Spring Security 7 整合CAS SSO 单点登录
java·spring·架构·sso
Jodie同志1 小时前
第16~23天:持久化、HITL、流式、MCP与安全
前端·后端·agent
Jodie同志1 小时前
第1~15天:原生Agent、RAG与LangGraph基础(完整代码实操)
前端·后端·agent
Zane19941 小时前
单例线程安全、生产者消费者、死锁:并发面试三连问串讲
java·后端
用户69371750013841 小时前
#DeepSeek+Pi‑Agent 王炸组合跑赢 Claude‑Code!
前端·人工智能·后端
Zane19941 小时前
类变量与实例变量:一个共享列表引发的线上事故
后端·python
Scene2161 小时前
AgentScope 2.0:2. 快速上手 从零构建生产级智能体
后端
前端一课2 小时前
用 TRAE Work 把项目踩坑经验沉淀成「团队可复用工程规范」,新人再也不重复掉坑
前端·后端
神奇小汤圆2 小时前
一文吃透 Spring 框架:原理、实践与面试全解析
后端