2013-05-02 85 views
0

在我的Spring應用程序中,我有兩個選擇框。彈簧動態下拉(國家/州)

第一個是Country列表

第二個是State名單。

當我們選擇一個國家相關的國家將被顯示。

在我們的Jsp中,我們可以設法使用JQuery來顯示列表。

但是如何在Spring(Java)中準備這個列表?

請推薦我如何在Java中執行此操作?

+0

如何準備的國家和國家名單..如果我們舉一個例子一個c國家,我會準備所有的國家名單和國家。 – 2013-05-02 05:32:10

+0

@AndrewThompson ..這是春天..當我之前問這個問題,我也看到你的問題.. – 2013-05-02 05:43:29

+0

您正在尋找Spring MVC 3 + Ajax解決方案(因爲你說你可以設法顯示數據使用jQuery)。在網絡上進行了一些搜索後,我發現[這個不錯的Q/A](http://stackoverflow.com/q/7196181/1065197)。對於你的財富,情況是國家/州。不過,如果你搜索關於spring mvc 3和ajax的話,它會更好**。 – 2013-05-02 06:00:59

回答

0

創建兩個bean接口國家及國家,如:

interface Country { 

State state; 

} 

interface State { 

    List<String> states; 

} 

實現這些接口與簡單的getter和setter方法,然後在spring.xml文件中定義一樣

<bean id ="CountryX" class="CountryImpl"> 
//Give reference to State bean say StateX in this case. 

<bean id ="StateX" class="StateImpl"> 
// here set the list of states 
+0

這個過程非常困難,我在想快捷方式得到所有的國家和州.. – 2013-05-02 05:40:34

+0

如果你想用Spring來做,你必須在spring配置文件中定義所有的配置。一旦你這樣做,那麼就沒有別的你必須做的了......它的完成 – 2013-05-02 05:42:54

+0

我很舒服只使用註釋..所以我沒有想到彈簧配置文件.. – 2013-05-02 05:46:18

0

一個更接近你的啓動配置將在您的中使用Map<String,List<String>> Spring bean xml

<bean id="beanName" class="package.CountryPojo"> 
    <property name "countryMap"> 
     <map> 
      <entry key="USA"> 
       <value> 
       <list merge="true"> 
        <value>MN</value> 
        <value>CA</value> 
       </list> 
       </value> 
      </entry> 
      <entry key="UK"> 
       <value> 
       <list merge="true"> 
        <value>XY</value> 
        <value>IJ</value> 
       </list> 
       </value> 
      </entry> 
     </map>  
    </property> 
</bean> 

有bean類像

class CountryPojo { 

    private Map<String,List<String>> countryMap; 

    //getters : setters 

} 
+0

感謝您的重播..正確使用Map Object,但在這種情況下,我們必須維護將近100個國家的XML。XML是沉重的..是他們的任何其他方式? – 2013-05-02 05:49:06

+0

最好的方法是將信息存儲在RDBMS中,因爲您選擇了spring,我認爲上述解決方案可以提供幫助 – sanbhat 2013-05-02 05:50:08

0

創建2個bean接口國家與國家象下面這樣:

interface Country { 

State state; 

} 

interface State { 

    List<String> states; 

} 

實現這些接口與getter和setter,然後初始化spring.xml文件中的配置在下面的方式:

<bean id ="CountryTemp" class="CountryImpl"> 
//Give reference to State bean say StateTemp in this case. 

<bean id ="StateTemp" class="StateImpl"> 
// here set the list of states