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();
    }
}
相关推荐
Csvn1 小时前
Nginx 配置与运维管理 — 从安装到 SSL 反向代理
后端
mqcode2 小时前
若依框架做大了怎么办?多模块 Maven 拆分的完整指南
后端
用户40269244819082 小时前
CRMEB Pro 新增后台接口全链路:路由、权限、验证器、返回格式一次讲清
前端·后端
考虑考虑3 小时前
Java实现hmacsha1加密算法
java·后端·java ee
掉鱼的猫3 小时前
Spring Boot → Solon 注解迁移实战指南:一张对照表说清楚
java·spring boot
程序边界3 小时前
lac_agent自愈链路上篇——crontab守护的那些坑与健康检查实战
后端
笨鸟飞不快3 小时前
从 MVC 到 DDD:一次真实的渐进式迁移实录
后端·架构
plainGeekDev3 小时前
广播接收器 → Flow + Lifecycle
android·java·kotlin
程序员威哥3 小时前
C#也能玩转YOLO:工业视觉原生推理方案,零Python依赖
后端
plainGeekDev3 小时前
EventBus → SharedFlow
android·java·kotlin