JsonProperty 的使用方法详解

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

JsonProperty 的使用方法详解

MartinEDM   2020-05-17 我要评论

这篇文章主要介绍了JsonProperty 的使用方法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

引入 依赖

<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.9.9</version>
<https://img.qb5200.com/download-x/dependency>

如果在springboot中 spring-boot-starter-web 包含了 此依赖

@JsonProperty 此注解用于属性上,作用是把该属性的名称序列化为另外一个名称,如把trueName属性序列化为name,@JsonProperty("name")。

@JsonProperty("name") 
  private String trueName; 
  
  public String getTrueName() { 
    return trueName; 
  } 
  
  public void setTrueName(String trueName) { 
    this.trueName = trueName; 
  }

使用这个注解,后端可以获取到前端与注解中同名的属性 ,后端以注解中的属性名返回给前端

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们