SoFunction
Updated on 2025-04-06

Methods in SpringBoot that ignore a property in entity class and do not return it to the front end (example details)

How to use Jackson

//The first method is to use @JsonIgnore annotation to annotate on the attribute, ignore the specified attributepublic  class PropertyDTO {
    @JsonProperty("disable")
    private Integer disable;
    @JsonProperty("placeholder")
    private String placeholder;
	//Use @JsonIgnore annotation, ignore this property, the front-end will not get the property    @JsonIgnore
    private String validate;
}
//The second way is to use @JsonIgnoreProperties to annotate on the class, and you can ignore the properties of the specified collection@JsonIgnoreProperties({"validate"})
public  class PropertyDTO {
    @JsonProperty("disable")
    private Integer disable;
    @JsonProperty("placeholder")
    private String placeholder;
    private String validate;
}

Note

public  class PropertyDTO {
    @JsonProperty("disable")
    private Integer disable;
    @JsonProperty("placeholder")
    private String placeholder;
	@JsonProperty("validate")
    @JsonIgnore
    private String validate;
}

Use simultaneously@JsonPropertyand@JsonIgnoreWhen it may cause@JsonIgnoreIf it fails, the front-end still gets this attribute.

When using fastjson
use@JSONField(serialize = false)annotation

This is the article about the method of ignoring a certain attribute in the entity class and not returning to the front-end in SpringBoot. This is the end. For more related SpringBoot attributes that do not return to the front-end content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!