JsonProperty 使用

引入 依赖  

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.9</version>
</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;  
    }  

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

原文地址:https://www.cnblogs.com/qin1993/p/11526351.html