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();
    }
}
相关推荐
Mem0rin4 分钟前
[Java/数据结构]顺序表之ArrayList
java·开发语言·数据结构
WarrenMondeville30 分钟前
4.Unity面向对象-接口隔离原则
java·unity·接口隔离原则
zb2006412030 分钟前
spring security 超详细使用教程(接入springboot、前后端分离)
java·spring boot·spring
啥咕啦呛30 分钟前
java打卡学习3:ArrayList扩容机制
java·python·学习
rrrjqy33 分钟前
Java基础篇(二)
java·开发语言
四七伵40 分钟前
Spring Boot项目中varchar字段为什么不用NULL?告别空指针从建表开始
数据库·后端
Mr.456743 分钟前
JDK17+Druid+SpringBoot3+ShardingSphere5 多表分库分表完整实践(MySQL+PostgreSQL)
java·数据库·spring boot·mysql·postgresql
tsyjjOvO43 分钟前
Spring Boot 入门
java·spring boot·后端
小码哥_常1 小时前
从云端坠落:PUT和DELETE请求在大公司的失宠之谜
后端
RuoyiOffice1 小时前
SpringBoot+Vue3+Uniapp实现PC+APP双端考勤打卡设计:GPS围栏/内网双模打卡、节假日方案、定时预生成——附数据结构和核心源码讲解
java·spring·小程序·uni-app·vue·产品运营·ruoyi