一、實(shí)體類文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-643205.html
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;
}
}
二、控制器類:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-643205.html
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();
}
}
到了這里,關(guān)于SpringBoot復(fù)習(xí)(30):@DateTimeFormat注解的使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!