使用fastjson无效
我想试试使用fastjson来格式化时间类型,但是失败了,麻烦老师帮我看一下,已经添加好了fastjson依赖,
而且重新配置了Tomcat将依赖添加进来了
public class Person {
private String name;
private Integer age;
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private Date birthday;
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
", birthday=" + birthday +
'}';
}
}

39
收起
正在回答
3回答
同学你好,这边测试,使用 @JSONField(format = "yyyy-MM-dd HH:mm:ss"),调用JSON.toJSONString(p1);可以格式化时间,如:

使用ajax返回页面的数据,可能是底层没有使用JSON.toJSONString(),所以无法格式化时间。我们请教了之前的老师,测试ajax也是无法格式化时间。
祝:学习愉快~
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星