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();
    }
}
相关推荐
wangkay8811 分钟前
【Java 转运营】Day05:抖音新号起号:对标账号运营全指南
java·新媒体运营
爱码猿21 分钟前
Springboot结合thymeleaf模板生成pdf文件
spring boot·后端·pdf
大飞哥~BigFei25 分钟前
新版chrome浏览器安全限制及解决办法
java·前端·chrome·安全·跨域
IT_陈寒29 分钟前
SpringBoot 3.2实战:5个性能优化技巧让你的应用提速50%
前端·人工智能·后端
{Hello World}32 分钟前
Java多态:三大条件与实现详解
java·开发语言
老蒋每日coding33 分钟前
Java解析Excel并对特定内容做解析成功与否的颜色标记
java·开发语言·excel
lang2015092833 分钟前
Java反射利器:Apache Commons BeanUtils详解
java·开发语言·apache
m0_7482459234 分钟前
SQLite 数据类型概述
java·数据库·sqlite
Mh_ithrha40 分钟前
题目:小鱼比可爱(java)
java·开发语言·算法