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();
    }
}
相关推荐
勤奋的知更鸟5 分钟前
Java编程之组合模式
java·开发语言·设计模式·组合模式
千|寻5 分钟前
【画江湖】langchain4j - Java1.8下spring boot集成ollama调用本地大模型之问道系列(第一问)
java·spring boot·后端·langchain
程序员岳焱19 分钟前
Java 与 MySQL 性能优化:MySQL 慢 SQL 诊断与分析方法详解
后端·sql·mysql
爱编程的喵19 分钟前
深入理解JavaScript原型机制:从Java到JS的面向对象编程之路
java·前端·javascript
龚思凯25 分钟前
Node.js 模块导入语法变革全解析
后端·node.js
天行健的回响27 分钟前
枚举在实际开发中的使用小Tips
后端
on the way 12330 分钟前
行为型设计模式之Mediator(中介者)
java·设计模式·中介者模式
保持学习ing32 分钟前
Spring注解开发
java·深度学习·spring·框架
wuhunyu33 分钟前
基于 langchain4j 的简易 RAG
后端
techzhi33 分钟前
SeaweedFS S3 Spring Boot Starter
java·spring boot·后端