我有一个捕获公民信息的表格,所以我有一个 Citizens 类
公民课
public class Citizens implements Serializable{
private int socialSecurityNumber;
private String fName;
private String lName;
private String oName;
private String photo;
private int countryId;
private String addLn1;
private String addLn2;
private String addLn3;......
基于 where_clause 返回一个公民列表/单个记录的DAO类,可以是任何值或值的组合。
if(where_clause != null){
//add WHERE to string
where_clause = "WHERE " + where_clause;
//get length of string
int where_clause_length = where_clause.length();
//remove last 'and' from string
where_clause = where_clause.substring(0, where_clause_length - 5);
logger.info(where_clause);
}
String sql = "SELECT socialSecurityNumber, fName, lName, oName, photo, countryId, addLn1, addLn2, addLn3,"
+"genderId, ethnicityId, skinColorId, eyeColorId, hairColorId, occupationId, phoneNo, maritalStatusId,"
+"noticableFeatures, weight, height, citizenTypeId, dob "
+"FROM crimetrack.tblcitizens " + where_clause;
logger.debug(sql);
List<Citizens> listOfCitizens = getJdbcTemplate().query(sql, new CitizensMapper());
return listOfCitizens;
在控制器中会发生以下情况:
if (user_request.equals("Query")){
logger.debug("about to preform query");
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!");
}
model.addAllAttributes(citizenManager.getListOfCitizens(citizen));
return new ModelAndView("citizen_registration");
}
}
这里的问题是此查询返回 3 条记录,但视图上只显示最后一条记录。下面是jsp的样子,它使用spring表单标签。我想要做的是添加下一条记录按钮,当用户单击下一条记录时,我想移动到列表中的下一条记录并将其显示给用户。如何实现这一点,如果不能使用这种方法完成,那么最好的方法是什么。我正在阅读有关分页的信息,但是我不确定如何将其实现到此应用程序中。有人可以帮助我或指导我如何解决这个问题:
jsp
<form:form id="citizenRegistration" name ="citizenRegistration" method="POST" commandName="citizens" action="citizen_registration.htm">
<div id="divRight" class="mainDiv">
<div class="divGroup" id="divCharInfo">
<label id="status"></label>
<div id="camera"></div>
<div><p><canvas id="canvas" height="240" width="320"></canvas><canvas id="canvas2" height="240" width="320"></canvas><form:errors path="photo" class="errors"/></div>
<form:input path="photo" id="photo" type="hidden"/>
<input id="upload" type="button" value="Take Photo">
<input id="retake" type="button" value="Re-Take Photo">
<ol>
<li>
<label>Select Gender</label>
<form:select path="genderId" id="genderId" title="Select Your Gender">
<form:options items = "${gender.genderList}" 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"/><form:errors path="weight" class="errors"/>
</li>
<li><form:label for="height" path="height">Enter Height <i>(feet)</i></form:label>
<form:input path="height" id="height" title="Enter Height"/><form:errors path="height" class="errors"/>
</li>