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();
    }
}
相关推荐
Java后端的Ai之路1 小时前
【JDK】-JDK 21 新特性内容
java·开发语言·后端·jdk·jdk21
普通网友3 小时前
PHP语言的正则表达式
开发语言·后端·golang
黎雁·泠崖3 小时前
Java常用类核心详解(七):正则表达式 Regex 从入门到实战
java·开发语言·正则表达式
sheji34163 小时前
【开题答辩全过程】以 婚纱影楼管理系统为例,包含答辩的问题和答案
java·eclipse
LuDvei3 小时前
LINUX文件操作函数
java·linux·算法
葵续浅笑4 小时前
从Spring拦截器到Filter过滤器:一次报文修改加解密的填坑经验
java·后端·spring
J2虾虾4 小时前
Spring Boot中使用@Scheduled做定时任务
java·前端·spring boot
snakeshe10105 小时前
Java集合框架深度解析:核心类库与实战应用
后端
肉肉不想干后端5 小时前
联合订单并发退款:一次分布式锁冲突的排查与思考
java