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();
    }
}
相关推荐
程序员梅雨20 分钟前
Linux & Shell 实用干货
linux·运维·服务器·后端·面试·php
lemon_sjdk22 分钟前
javafx-Image图像(2)
java·javafx
大牧师28 分钟前
TypeORM 入门教程
后端·sql·mysql·orm·nest·typeorm
IT_陈寒29 分钟前
Vite静态资源路径这个大坑害我调了一下午
前端·人工智能·后端
武哥聊编程30 分钟前
【AI实战项目】基于SpringAI+Springboot+Vue的AI面试刷题训练平台
vue.js·人工智能·spring boot·springai
oliver_sys_log38 分钟前
绕过 Yearning 查询体验限制:我做了一个 DataGrip 只读 SQL 代理
后端·mysql
小七在进步39 分钟前
C++入门(2)
java·jvm·c++
水深火乐40 分钟前
golang-jwt v5 入门
后端
carson95542 分钟前
基于springboot和vue的文本文件上传下载在线编辑功能
后端
To0R43 分钟前
Agent 上线前必须过的五道门(附 Spring Boot 实现)
java