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();
    }
}
相关推荐
秋野酱14 分钟前
Spring Boot 项目的计算机专业论文参考文献
java·spring boot·后端
码视野20 分钟前
基于Spring Boot和Vue的在线考试系统架构设计与实现(源码+论文+部署讲解等)
vue.js·spring boot·系统架构
士别三日&&当刮目相看21 分钟前
数据结构*优先级队列(堆)
java·数据结构
香饽饽~、26 分钟前
【第二篇】 初步解析Spring Boot
java·spring boot·后端
坎布里奇37 分钟前
java -jar命令运行 jar包时如何运行外部依赖jar包
java·pycharm·jar
冷yan~1 小时前
GitHub文档加载器设计与实现
java·人工智能·spring·ai·github·ai编程
你是狒狒吗1 小时前
消息队列了解一哈
后端
CodeBlossom1 小时前
java加强 -stream流
java·windows·python
理想奋斗中1 小时前
idea中Lombok失效的解决方案
java·intellij-idea·lombok