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();
    }
}
相关推荐
代龙涛2 小时前
WordPress 主题初体验:从 style.css 到 index.php、single.php 简单实战
后端·php·wordpress
zzb15808 小时前
RAG from Scratch-优化-query
java·数据库·人工智能·后端·spring·mybatis
wuqingshun3141598 小时前
如何停止一个正在退出的线程
java·开发语言·jvm
Barkamin9 小时前
队列的实现(Java)
java·开发语言
必胜刻9 小时前
RESTful 基础:资源、路径与方法对应关系详解
后端·restful
XPoet9 小时前
AI 编程工程化:Hook——AI 每次操作前后的自动检查站
前端·后端·ai编程
骇客野人10 小时前
自己手搓磁盘清理工具(JAVA版)
java·开发语言
J2虾虾10 小时前
在SpringBoot中使用Druid
java·spring boot·后端·druid
清风徐来QCQ10 小时前
Java笔试总结一
java·开发语言
10Eugene10 小时前
C++/Qt自制八股文
java·开发语言·c++