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();
    }
}
相关推荐
我要神龙摆尾3 分钟前
约定俗成的力量--java中泛型的意义和用法
java·开发语言
老友@10 分钟前
分布式事务完全演进链:从单体事务到 TCC 、Saga 与最终一致性
分布式·后端·系统架构·事务·数据一致性
毅炼12 分钟前
hot100打卡——day14
java·数据结构·算法·leetcode·ai·深度优先·哈希算法
C雨后彩虹23 分钟前
优雅子数组
java·数据结构·算法·华为·面试
一嘴一个橘子26 分钟前
springmvc 全局异常处理 and 拦截器
java
wangmengxxw26 分钟前
SpringAI-mysql
java·数据库·人工智能·mysql·springai
Coder_Boy_29 分钟前
基于SpringAI的在线考试系统-数据库设计核心业务方案
java·数据库·spring boot·ddd·tdd
一嘴一个橘子31 分钟前
springmvc 参数校验
java
shehuiyuelaiyuehao1 小时前
String的杂七杂八方法
java·开发语言
木井巳1 小时前
【递归算法】计算布尔二叉树的值
java·算法·leetcode·深度优先