gpt4 book ai didi

java - 如何从java中另一个类的bean获取值

转载 作者:行者123 更新时间:2023-12-01 15:59:41 24 4
gpt4 key购买 nike

我正在一个类中设置 java bean 的值。如何获取另一个类中的值有人可以举个例子吗?

import java.util.ArrayList;

public class HomeBean {
String indexname="";
String lastvalue="";
String changepercentage="";
ArrayList aindexname=new ArrayList();
ArrayList alastname=new ArrayList();
ArrayList alastpercentage=new ArrayList();
public String getIndexname() {
return indexname;

}
public void setIndexname(String indexname) {
this.indexname = indexname;
System.out.println("******index name is *****"+indexname);
aindexname.add(indexname);

}

public String getLastvalue() {
return lastvalue;
}
public void setLastvalue(String lastvalue) {
this.lastvalue = lastvalue;
}
public String getChangepercentage() {
return changepercentage;
}
public void setChangepercentage(String changepercentage) {
this.changepercentage = changepercentage;
}
public ArrayList getArrayListIndexName()
{
for(int i=0;i<aindexname.size();i++)
{
System.out.println("####indexname is######"+aindexname.get(i).toString());
}

return aindexname;
}

public ArrayList getArrayListLastValue()
{
return alastname;

}

public ArrayList getArrayListChangePercentage()
{

return alastpercentage;
}




}

在一个类中设置值

 mport java.util.ArrayList;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class DomTableParser
{

ArrayList listTable=new ArrayList();
public ArrayList parseXmlFile(String tableservicevalue){
//get the factory
Document doc;
StringtoDocument stdoc=new StringtoDocument();
doc=stdoc.getDocument(tableservicevalue);

//System.out.println("Information of all employees");


HomeBean bean=new HomeBean();
Element docEle = doc.getDocumentElement();




NodeList indexNode = docEle.getElementsByTagName("INDEX");
if(indexNode != null && indexNode.getLength() > 0)
{
for(int i = 0 ; i < indexNode.getLength();i++)
{
Element homeElmnt = (Element)indexNode.item(i);

DomParserTableDataSet dataSet=new DomParserTableDataSet();
String indexName = homeElmnt.getAttribute("INDEX_NAME");
String lastValue=homeElmnt.getAttribute("LAST_VALUE");
String changePercentage=homeElmnt.getAttribute("CHANGE_PERCENTAGE");
//String questgroupid=loginElmnt.getAttribute("ID");
bean.setIndexname(indexName);
bean.setLastvalue(lastValue);
bean.setChangepercentage(changePercentage);
bean.getArrayListIndexName();
dataSet.setIndexName(indexName);
dataSet.setLastValue(lastValue);
dataSet.setChangePercentage(changePercentage);
listTable.add(dataSet);



}
}


return listTable;
}




}

最佳答案

关于java - 如何从java中另一个类的bean获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4277683/

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