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();
    }
}
相关推荐
架构师沉默3 分钟前
为什么一个视频能让全国人民同时秒开?
java·后端·架构
生命不息战斗不止(王子晗)11 分钟前
mysql基础语法面试题
java·数据库·mysql
umeelove3514 分钟前
Java进阶(ElasticSearch的安装与使用)
java·elasticsearch·jenkins
redaijufeng17 分钟前
Node.js(v16.13.2版本)安装及环境配置教程
java
齐齐大魔王31 分钟前
linux-线程编程
java·linux·服务器
掘金码甲哥37 分钟前
同样都是九年义务教育,他知道的AI算力科普好像比我多耶
后端
sthnyph1 小时前
SpringBoot Test详解
spring boot·后端·log4j
我真会写代码1 小时前
Redis核心特性详解:事务、发布订阅与数据删除淘汰策略
java·数据库·redis
饼干哥哥1 小时前
搭建一个云端Skills系统,随时随地记录TikTok爆款
前端·后端
IT 行者1 小时前
LangChain4j 集成 Redis 向量存储:我踩过的坑和选型建议
java·人工智能·redis·后端