0

我有一个捕获公民信息的表格,所以我有一个 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> 
4

1 回答 1

1

试试这个......在控制器中

model.addAttribute("citizens",citizenManager.getListOfCitizens(citizen));

现在在您的 jsp 中执行以下操作: 1. 在 jsp 页面顶部

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


添加此代码 2. 现在将此代码添加到您的 html 正文中

<c:forEach items="${citizens}" var="citizen">
First name:- ${citizen.fName} , Last Name:- ${citizen.lName}
</c:forEach>

希望这可以帮助

于 2013-03-05T16:24:04.753 回答