我不确定如何在 Spring MVC 表单标签中定义 value 属性。我正在查询数据库,我想将数据返回给 jsp。我以列表的形式将一个对象返回给视图。我想知道如何为选项列表和输入框编写属性值。下面是我的代码:
jsp
<form:form id="citizenRegistration" name ="citizenRegistration" method="POST" commandName="citizens" action="citizen_registration.htm">
<li>
<label>Select Gender</label><form:select path="genderId" id="genderId" title="Select Your Gender"><form:options items = "${gender.genderList}" selected=???? itemValue="genderId" itemLabel="genderDesc" />
</form:select><form:errors path="genderId" class="errors"/>
</li>
<li><form:label for="weight" path="weight">Enter Weight <i>(lbs)</i></form:label>
<form:input path="weight" id="weight" title="Enter Weight" value= ???/><form:errors path="weight" class="errors"/>
</li>
爪哇道
函数返回:..........................
List<Citizens> listOfCitizens = getJdbcTemplate().query(sql, new CitizensMapper());
return listOfCitizens;
控制器
if (user_request.equals("Query")){
logger.debug("about to preform query");
citizenManager.getListOfCitizens(citizen);
if(citizenManager.getListOfCitizens(citizen).isEmpty()){
model.addAttribute("icon","ui-icon ui-icon-circle-close");
model.addAttribute("results","Notice: Query Caused No Records To Be Retrived!");
}
//how do i return the List<Citizens> listOfCitizens
//or what should be done to send the user the data from the database
return new ModelAndView("citizen_registration");
}