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();
    }
}
相关推荐
沉静的小伙23 分钟前
在微服务中使用领域事件
java·运维·微服务
GoGeekBaird28 分钟前
我最近在写 BeeWeave,想把 Agent 用过的上下文留住
后端·github·ai编程
醇氧34 分钟前
Spring 容器 Map 注入机制详解
java·后端·spring
梨子同志35 分钟前
MyBatis-Plus
后端
doiito1 小时前
微服务资源优化新思路:Sablier + Podman 实现按需启动与自动休眠
后端·微服务·性能优化
接着奏乐接着舞。1 小时前
【2026年7月最新】69道RAG面试题
前端·人工智能·后端·aigc·embedding·rag
栈溢出了1 小时前
Java Lambda 表达式笔记
java·开发语言·intellij-idea
会周易的程序员1 小时前
使用 pybind11 封装 C++ 日志库 microLog 为 Python 模块
java·c++·python·物联网·架构·日志·aiot
edwarddamon1 小时前
Spring Cloud Gateway 全链路 traceId 传递方案
后端