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();
    }
}
相关推荐
JaguarJack4 分钟前
Laravel Go 高性能全栈框架发布
后端·go·laravel·服务端
钱栈up3 小时前
烧结趋势页台车速度曲线凭空消失:一次\\\"去重\\\"误杀的配置修复
后端·测试
钱栈up3 小时前
删 18 个模块全程零报错:烧结系统单体拆微服务的 P0 实操
spring boot·微服务
刘小灰8 小时前
返璞归真,我开始更新博客了
前端·后端
一条Go9 小时前
巡检报告:把一次性排障变成可复跑的任务
后端·github
一条Go9 小时前
SQL 实验室:只读靠两把锁,DDL 靠模板
后端·github
一条Go9 小时前
维护窗口与升级策略:静默和升级怎么共存
后端·github
一条Go9 小时前
应用商店:版本、发布与部署为什么必须拆成三个阶段
后端·github
郝学胜-神的一滴10 小时前
Effective STL 条款15:注意字符串实现上的差异
java·开发语言·数据结构·c++·算法·visualstudio
sharemylove10 小时前
Java学习笔记 —— 面向对象专题
java·开发语言·笔记·学习·课程设计