写在前面的话
系列教程都是从网络上收集和本人的理解所编辑而成,仅供广大爱好者学习所用,请尊重本人的劳动成果。欢迎评论指正和转帖!(请保留连接谢谢!)
123
一、主要区别在于Demo.java和HelloController.java两个文件,其它的和上一篇一样。
二、Demo.java
package com.fs;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
public class Demo {
private int id;
private String name;
// com.alibaba.fastjson.annotation.JSONField
@JSONField(format = "yyyy-MM-dd HH:mm")
private Date createTime;
@JSONField(serialize = false)
private String mark;
public String getMark() {
return mark;
}
public void setMark(String mark) {
this.mark = mark;
}
public int getId() {
return id;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.fs;
import java.util.Date;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/getJson")
public Demo getJson() {
Demo demo = new Demo();
demo.setId(2);
demo.setName("lisi");
demo.setCreateTime(new Date());
demo.setMark("这里是不显示的备注");
return demo;
}
}