我已成功写入spring.xml中的表,如下所示。
<bean id="kpTable" class="com.kp.util.MultiMapToTableConverter" factory-method="createTableFactory"
scope="prototype">
<constructor-arg name="map">
<util:map>
<entry key="usa">
<util:map>
<entry key="alabama" value="Montgomery" />
<entry key="Arizona" value="Phoenix" />
<entry key="Arkansas" value="Little Rock" />
<entry key="California" value="Sacramento" />
<entry key="Colorado" value="Denver" />
</util:map>
</entry>
<entry key="uk">
<util:map>
<entry key="Yorkshire" value="York" />
<entry key="Norfolk" value="Norwich" />
<entry key="Oxfordshire " value="Oxford" />
<entry key="Northamptonshire " value="Northampton" />
<entry key="Nottinghamshire " value="Nottingham" />
</util:map>
</entry>
<entry key="in">
<util:map>
<entry key="maharashtra" value="mumbai" />
<entry key="karnataka" value="bangalore" />
<entry key="tamil nadu" value="chennai" />
<entry key="west bengal " value="kolkata" />
</util:map>
</entry>
</util:map>
</constructor-arg>
</bean>
MultiMapToTableConverter.java
public class MultiMapToTableConverter {
public static Table<String, String, String> createTableFactory(Map<String, Map<String, String>> map) {
Table<String, String, String> table = HashBasedTable.create();
for (Map.Entry<String, Map<String, String>> outerEntrySet : map.entrySet()) {
for (Map.Entry<String, String> innerEntrySet : outerEntrySet.getValue().entrySet()) {
table.put(outerEntrySet.getKey(), innerEntrySet.getKey(), innerEntrySet.getValue());
}
}
return table;
}
}
MyTest类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:spring-kp-context.xml"})
public class KPTableTest {
@Autowired
private Table<String, String, String> table;
@Test
public void kpTest(){
System.out.println(table.get("usa", "alabama"));
System.out.println(table.get("in", "karnataka"));
System.out.println(table.get("in", "tamil nadu"));
}
现在我有一些基于实施的问题
Map<String,Map<String,String>>
Vs HashBasedTable
。