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();
    }
}
相关推荐
风象南13 分钟前
Token太贵?我用这个数据格式把上下文窗口扩大2倍
人工智能·后端
Victor35615 分钟前
MongoDB(17)如何在MongoDB中创建集合?
后端
摸鱼的春哥28 分钟前
春哥的Agent通关秘籍13:实现RAG查询
前端·javascript·后端
Victor35635 分钟前
MongoDB(16)如何在MongoDB中创建数据库?
后端
勇哥java实战分享9 小时前
程序员的明天:AI 时代下的行业观察与个人思考
后端
掘金码甲哥11 小时前
超性感的轻量级openclaw平替,我来给你打call
后端
用户83562907805114 小时前
无需 Office:Python 批量转换 PPT 为图片
后端·python
啊哈灵机一动14 小时前
使用golang搭建一个nes 模拟器
后端
日月云棠15 小时前
各版本JDK对比:JDK 25 特性详解
java
间彧15 小时前
SpringBoot + ShardingSphere 读写分离实战指南
后端