我在application.properties中将日期格式设置为spring.jackson.date-format=dd-MM-yyyy HH:mm:ss
,但杰克逊将其格式化为2017-08-19T10:08:38
。
我在属性中提到的格式有问题,或者默认情况下它只支持一种格式吗?
答案 0 :(得分:0)
Spring Boot jackson日期格式适用于以下示例:
申请类:
@SpringBootApplication
@RestController
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@PostMapping("/format")
public Model postModel(@RequestBody Model model){
System.out.println("Model model"+model.toString());
return model;
}
protected static class Model{
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Model(Date date) {
super();
this.date = date;
}
public Model() {
super();
}
@Override
public String toString() {
return "Model [date=" + date + "]";
}
}
}
application.properties :
spring.jackson.date-format=dd-MM-yyyy HH:mm:ss
输入:
{
"date": "10-12-2016 10:00:00"
}
输出:
{
"date": "10-12-2016 10:00:00"
}