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();
    }
}
相关推荐
初学AI的小高13 分钟前
RAG 知识库更新实战:增量索引、版本控制与可验证删除
后端·agent
山楂树の24 分钟前
Java 字符串高效处理:StringBuilder、StringBuffer、StringJoiner
java·开发语言
fishfinal1 小时前
VitePress 架构重构实录:拒绝扁平与耦合,重构你的独立文档项目
后端
Java内核笔记1 小时前
方法级 trace 看不出第几轮:给 Agent 补一层轮次维度
人工智能·spring boot·后端
数据库小学妹1 小时前
数据库容量规划:四个数与扩容触发线
运维·数据库·后端
AAA修煤气灶刘哥1 小时前
DSH Super-agent 双层架构:如何兼顾后台执行与持续响应
人工智能·后端·设计模式
泡海椒1 小时前
jquick-pdf 资源使用率报表模板:政务云集群水位的图表版与表格版怎么选
后端
用户5080070546281 小时前
1元机器到手后,我拿它跑了一套微服务测试环境
后端
郭生1 小时前
dedecms等php类cms静态生成速度慢或超时原因及解决方法
后端
Gopher_HBo1 小时前
Go pprof:五个字段,凭什么管住六种剖析?
后端