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();
    }
}
相关推荐
在繁华处4 分钟前
Java从零到熟练(九):并发编程基础
java·开发语言
木头程序员9 分钟前
SSM框架学习笔记
java·开发语言·mysql·spring·maven
李白你好12 分钟前
页面资产梳理 · 技术指纹识别 · Spring 端点探测
java·后端·spring
用户17537212403314 分钟前
02《面向对象设计原则:SOLID原则实战解析》
后端
一起逃去看海吧14 分钟前
dify-03
java·linux·开发语言
我是一颗柠檬21 分钟前
【Java后端技术亮点】热Key探测与本地缓存二级防护:Redis热点问题的终极解决方案
java·redis·后端·缓存·中间件
thatway198925 分钟前
理想汽车开源技术-2星环OS开源车载操作系统介绍
后端
阿聪谈架构28 分钟前
第13章:AI异步与生产部署 —— 让 AI 服务稳定高效地面向用户
人工智能·后端
LucianaiB1 小时前
耗时30天,DocPilot Qwen正式开源:一个免费无广的开源文档 AI 助手
前端·后端
Refrain_zc1 小时前
Android 音视频通话核心 —— 音频编码(AAC)完整解析
java