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();
    }
}
相关推荐
架构师沉默1 分钟前
女孩去旅行,给男朋友带回了一个难解的 Bug
java·后端·架构
月光宝鉴2 分钟前
如何将excel中文件转为json
后端
xu_ws8 分钟前
Spring-ai项目-deepseek-6-哄哄模拟器
java·人工智能·spring
刘 大 望11 分钟前
SpringAI Tool Calling(工具调用)
java·spring boot·spring·ai·maven·intellij-idea·文心一言
222you11 分钟前
Java 并发编程(1)
java·开发语言
stark张宇29 分钟前
告别混乱接口:RESTful API 规范实战指南
后端
岁岁种桃花儿36 分钟前
kubenetes从入门到上天系列第十九篇:Kubernetes安装Nginx ingress controller
java·nginx·kubernetes
做一个AK梦44 分钟前
RedisForValueService.setIfAbsent()
java·分布式
uzong1 小时前
Dubbo 版本升级 3.0.10 升级到 3.1.11 ,3.0.10升级到3.2.16 (过程素材、仅供参考)
后端