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();
    }
}
相关推荐
烤代码的吐司君5 分钟前
Redis 数据结构 ZSet, BIT, HyperLogLog,Geo 空间数据
redis·后端
苏三说技术9 分钟前
为什么越来越多的人使用FastAPI?
后端
JavaGuide11 分钟前
比 iTerm2 更适合 Claude Code/Codex 的终端,我换成 Ghostty 了
人工智能·后端
tntxia19 分钟前
Mybatis的日志输入
java
DyLatte1 小时前
AI 时代,最危险的不是被替代,而是努力不沉淀
前端·后端·程序员
神奇小汤圆1 小时前
架构师必备:CPU使用率不均匀排查
后端
神奇小汤圆1 小时前
Multi-Agent 执行闭环:AI Coding 真正进生产,要靠模型分工和工程护栏
后端
柒和远方1 小时前
从一次工程审查看 AI 学习产品的边界兜底:RAG 资料链路一致性实战
前端·后端·架构
亦暖筑序2 小时前
Java 8老系统Browser Agent实战:三层拦截把AI操作后台变成可审计流程
java·后端·设计模式
用户34232323763172 小时前
GPIO控制与按键中断入门
后端