我正在使用Spring MVC,我試圖將HashMap和ArrayList值傳遞給我的視圖文件。但我找不到達到此目的的方法。傳遞HashMap和ArrayList值來查看文件
你能幫我嗎?
我的控制器Mehtod
@RequestMapping(value="/do_register", method= RequestMethod.GET)
public ModelAndView RegistrationForm(@ModelAttribute Subscriber subscriber, BindingResult result)
{
HashMap<Integer, String> interest = new HashMap<Integer, String>();
interest.put(1,"Java");
interest.put(2,"PHP");
interest.put(3, "Both");
List<City> myCities = subService.getCity();
// I want to pass both "myCities" and "interest" to my view File
return new ModelAndView("regForm", "records", " ");
}
形式
<c:url var="action" value="/register" ></c:url>
<form:form action="${action}" modelAttribute="subscriber" method="POST" >
<div>
<label>City</label>
<form:select path="city">
<c:forEach items="${records}" var="city">
<option value="${city.cityId}">${city.cityName}</option>
</c:forEach>
</form:select>
</div>
<div>
<label>Interests</label>
<form:checkboxes path="interest" items="${records.interests}"/>
</div>
<input type="submit" value="Submit">
</form:form>