gpt4 book ai didi

Java Bean :How to fetch the values from List from another bean

转载 作者:行者123 更新时间:2023-12-01 18:37:21 25 4
gpt4 key购买 nike

我有一个 bean,我将另一个 beanlist 放入其中,并且我想访问该内部 bean。

我的第一个 Bean 是:

public class FirstDTO {
private String Fname= "";
private String name= "";
private List<studentTransactionDTO> studentTransactionDTOList = new ArrayList<studentTransactionDTO>();
getter and setters....

我的第二个 Bean 是:

public class studentTransactionDTO {

private String age= "";
private String lName = "";
private String marks = "";
getter and setters....

请给我一些从内部 bean 中检索值的建议。

问候。

最佳答案

你可以试试这个方法

    FirstDTO  firstDTO=new FirstDTO();// FirstDTO instance
List<studentTransactionDTO> list=firstDTO.getStudentTransactionDTOList();
// list of studentTrasactionDTO in firstDTO

String age=list.get(0).getAge(); // name of first element in list

您可以按如下方式迭代整个列表

    for(studentTransactionDTO i:list){
i.getName()// you can access i's properties.
}

关于Java Bean :How to fetch the values from List<bean> from another bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21380973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com