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();
    }
}
相关推荐
掘金码甲哥1 小时前
1分钟买不了吃亏系列: nginx动态域名解析
后端
神奇小汤圆2 小时前
2026大厂Java岗面试记录:八股+场景+项目+AI,一文讲透快速上岸路径(含答案)
后端
神奇小汤圆2 小时前
我说MySQL每张表最好不超过2000万条数据,面试官让我回去等通知?
后端
HuanYu2 小时前
JDK实现动态代理
后端
袋鱼不重2 小时前
解决 Web 端图片预览与下载颜色不一致的一种工程方案
前端·后端
lizhongxuan2 小时前
Agent 的 Code-driven Assembly
后端
稀土熊猫君3 小时前
一个人能做出什么开源项目?
vue.js·后端·开源
lizhongxuan3 小时前
Agent Runtime 中的 Code-driven Assembly
后端