Spring-如何从对象列表中删除属性? [英] Spring- How to remove a property from a list of Objects?
问题描述
我有一个具有以下属性的人"实体,
I have an Entity "Person" which has following properties,
Id
Name
F-Name
Age
Address
当我在Person上调用存储库函数findAll()时,它将返回一个Persons列表.
When I call a repository function findAll() on Person, it returns a list of Persons.
List<Person> list = somefuntionToConvertIterableToList(personRepository.findAll());
此列表包含多个人员类型"对象.
this list has multiple objects of Person Type.
人员...... ... Id1,Name1,F-Name1,Age1,Address1
Person ...... Id1,Name1, F-Name1, Age1, Address1
人员....... IdN,NameN,F-NameN,AgeN,地址N
Person .......IdN,NameN, F-NameN, AgeN, AddressN
我需要从所有人中删除"Id",我该怎么办?
I need to remove "Id" from all Persons, what should I do?
我知道我们可以使用删除"来删除列表中的元素,但是如何删除元素中的属性?
I know we can use "remove" to delete an element of list, but how to delete a property with in an element?
推荐答案
我认为您需要使用:@JsonIgnore in Id如下:
I think you need used : @JsonIgnore in Id look like:
@JsonIgnore
Field you want remove in reponse.
或者您可以创建DTO,然后将要返回的所有字段都显示为:
Or you can create DTO and put all field you want return look like :
public class PersonDTO {
//all field you want return
}
这篇关于Spring-如何从对象列表中删除属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!