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();
    }
}
相关推荐
我不会起名字3225 分钟前
未接入最终读上限的参数:`websocketMaxMsgLen` 与 12.5 倍差距
后端·websocket·go·即时通讯·im·故障排查
一条Go44 分钟前
接收方合并去重:同一个人为什么只该收到一次通知
后端·架构·github
北漂人Java1 小时前
基于 Spring AI Alibaba WorkFlow 构建 Java 生产级 AI Agent
java·人工智能·spring
张一凡931 小时前
给 Coding Agent 加一道"架构闸门":Jin 是如何做到"先审架构、再写代码、不漂移"的
前端·后端·agent
Jvav练习生1 小时前
AI Agent 总在关键时刻“失忆”翻车?一文讲透上下文工程(附可运行 Python 代码)
后端
用户112936112192 小时前
编译全绿,上线就崩:MyBatis 五层方法名大小写埋下的坑
java
leo在掘金2 小时前
只挂了11小时,5000台开发机被塞进SSH公钥
后端·架构
xjz18422 小时前
Rust 运算符优先级:括号不只用来改变顺序
后端
写码跑山的老艾2 小时前
为什么有了 MySQL,还要 Redis 和 Elasticsearch?从一件商品看数据系统的权衡
后端