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();
    }
}
相关推荐
mzhan01722 分钟前
Linux: compare的直观性
java·linux·服务器
mask哥28 分钟前
力扣算法java实现汇总整理(下)
java·算法·leetcode
平凡但不平庸的码农34 分钟前
Go 错误处理详解
开发语言·后端·golang
小陈的进阶之路34 分钟前
Python系列课(2)——判断
java·前端·python
刚子编程37 分钟前
C# Join 进阶:GroupJoin、性能对决与自定义比较器
java·servlet·c#·join
漫随流水43 分钟前
IDEA快速生成构造方法(空参、带参)
java·intellij-idea
spencer_tseng1 小时前
Spring Boot 3.0+ jakarta.*
java·spring boot
Bat U1 小时前
JavaEE|文件操作和IO
java·开发语言
DavidSoCool2 小时前
Spring AI Alibaba ReactAgent 调用Tool 实现多轮对话
java·人工智能·spring·多轮对话·reactagent
PRINT!2 小时前
个人财富全景管理系统 AssetMe【内容均为AI制作】
spring boot·信息可视化·ai编程