简体   繁体   中英

How to pass List<String> from controller to <form:select> in Spring 4.0.0

I have an object with countryName attribute and method getCountryName() get all countryName from database by using below query:

SELECT DISTINCT countryName from jobs

Now i want to pass this list into a form at jsp page as below:

<form:form>
<form:select>
<form:options> List of country name </form:options>
</form:select>
</form:form>

Anyone have ideas? I'm using Spring 4.0.0 REALEASE.

For easier understanding, i already had an annotation in my controller

@ModelAttribute("countries")
public List<String> getListCountryName(){
return dao.getCountryName() ; 

}

How can i pass that list to view in spring's form tag?

Write some thing like this:

 <form:form>
    <form:select path="commandAttribute">
          <form:option value="-" label="List of country namet"/>
          <form:options items="${countryList}" itemValue="countryName " itemLabel="countryName "/>
     </form:select>
    </form:form>

Reference http://www.mkyong.com/spring-mvc/spring-mvc-dropdown-box-example/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM