[英]How do I retrieve a key of ArrayList<String> from a Hashtable?
[英]How do I retrieve particular value from an ArrayList<String> in Spring
客户端程序应显示所有玩家的详细信息及其对应的国家/地区详细信息。 如果给定一个国家名称,它还应该显示属于该国家的所有玩家名称。 两名球员属于一个国家,另外 3 名球员属于另一个国家。
我在我的 beans.Spring 中的beans.xml文件中声明了 4 个列表。 我想知道如何检索特定的列表值?
我的 beans.xml 文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="player" class="com.my.bean.SpringIOC5">
<property name="playerId">
<list>
<value>p1</value>
<value>p2</value>
<value>p3</value>
<value>p4</value>
<value>p5</value>
</list>
</property>
<property name="playerName">
<list >
<value>pn1</value>
<value>pn2</value>
<value>pn3</value>
<value>pn4</value>
<value>pn5</value>
</list>
</property>
<property name="country" ref="cnty"></property>
</bean>
<bean id="cnty" class="com.my.bean.Country">
<property name="countryId">
<list>
<value>c1</value>
<value>c2</value>
<value>c3</value>
<value>c4</value>
<value>c5</value>
</list>
</property>
<property name="countryName">
<list>
<value>cn1</value>
<value>cn2</value>
<value>cn3</value>
<value>cn4</value>
<value>cn5</value>
</list>
</property>
</bean>
</beans>
我的播放器 class:
public class SpringIOC5 {
//public class Player
private List<String> playerId;
private List<String> playerName;
private Country country;
public SpringIOC5() {
super();
// TODO Auto-generated constructor stub
}
public SpringIOC5(List<String> playerId, List<String> playerName, Country country) {
super();
this.playerId = playerId;
this.playerName = playerName;
this.country = country;
}
public List<String> getPlayerId() {
return playerId;
}
public void setPlayerId(List<String> playerId) {
this.playerId = playerId;
}
public List<String> getPlayerName() {
return playerName;
}
public void setPlayerName(List<String> playerName) {
this.playerName = playerName;
}
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
this.country = country;
}
@Override
public String toString() {
return "SpringIOC5 [playerId=" + playerId + ", playerName=" + playerName + ", country=" + country + "]";
}
}
我的国家 class:
public class Country {
private List<String> countryId;
private List<String> countryName;
public Country() {
super();
// TODO Auto-generated constructor stub
}
public Country(List<String> countryId, List<String> countryName) {
super();
this.countryId = countryId;
this.countryName = countryName;
}
public List<String> getCountryId() {
return countryId;
}
public void setCountryId(List<String> countryId) {
this.countryId = countryId;
}
public List<String> getCountryName() {
return countryName;
}
public void setCountryName(List<String> countryName) {
this.countryName = countryName;
}
@Override
public String toString() {
return "Country [countryId=" + countryId + ", countryName=" + countryName + "]";
}
}
使用 ArrayList class 的方法获取具体值。
countryId.get(indexNo.);
在 oracle java 文档中查看更多方法
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.