Json return data to the front end, to ignore the null attribute field

There are two main ways:

  1. Add annotations on the return of class:
    @JsonInclude(JsonInclude.Include.NON_NULL)
    This annotation can be null attributes in the entity class automatically ignored.

  2. Springboot project can modify the configuration file application.yml Global Auto ignored:

spring:
  jackson:
    default-property-inclusion: NON_NULL
  1. Other methods such as via Gson tools or methods, in the form of annotated on the interface, is similar concept.
Published 42 original articles · won praise 10 · views 7052

Guess you like

Origin blog.csdn.net/MCJPAO/article/details/103108795