springmvc返回json格式数据(个人笔记,非教程)

maven依赖(之后返回的结果,默认就会自动进行json序列化)

	<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.9.8</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.11.3</version>
    </dependency>

java

 @PostMapping("/test77")
  @ResponseBody
  public User test7() {
    User user = new User();
    user.setUserName("pjw");
    user.setPassword("123456");
    return user;
  }
处理Date(不处理的话,默认返回时间戳)
public class User {
    private String userName;
    private String password;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")//响应格式,timezone解决时区问题
    @DateTimeFormat(pattern = "yyyy-MM-dd")//接收请求时格式
    private Date date;
   }
上一篇:安了个vs 2008 express后,诡异asp.net Ajax PageMethods的问题,怎么解决?


下一篇:先别一窝蜂的踏入互联网医疗 了解什么才是打开互联网医院的正确姿势