あいまい検索(例:「田」と入力)を行った際に検索結果画面に遷移すると、テキストに入力した「田」が消えてしまいます。
またプルダウン選択の部署名検索も同様です。
遷移後も何で検索をかけたかが分かるように保持した状態にしたいのですが、どのように記述すればよいのでしょうか。
コード <div class="title">社員名検索</div> <div class="form"> <form method="post" th:action="@{/find}"> <input type="text" name="empName" /> <input type="submit" value="検索" /> </form> </div> <div class="title">部署名検索</div> <div class="form"> <form method="post" th:action="@{/findDept}"> <select name="deptId"> <option value="1" selected="selected">営業部</option> <option value="2">経理部</option> <option value="3">総務部</option> </select> <input type="submit" value="検索" /> </form> </div>
コード <table class="emp_list_table"> <tr> <th class="empId">社員ID</th> <th class="empName">社員名</th> <!-- <th:block th:if="${session.employee.authority == 2}"> --> <th class="gender">性別</th> <th class="address">住所</th> <th class="birthday">生年月日</th> <th class="authority">権限</th> </th:block> <th class="deptName">部署名</th> <!-- <th:block th:if="${session.employee.authority == 2}"> --> <th class="button" >変更</th> <th class="button" >削除</th> </th:block> </tr> <tr th:each="employee:${employees}"> <td th:text="${employee.empId}"></td> <td th:text="${employee.empName}"></td> <!-- <th:block th:if="${session.employee.authority == 2}"> --> <td> <div th:if="${employee.gender == 1}">男性</div> <div th:if="${employee.gender == 2}">女性</div> </td> <td th:text="${employee.address}"></td> <td th:text="${#dates.format(employee.birthday, 'yyyy/MM/dd')}"></td> <td> <div th:if="${employee.authority == 1}">一般</div> <div th:if="${employee.authority == 2}">管理者</div> </td> </th:block> <td th:text="${employee.department.deptName}"></td> <!-- <th:block th:if="${session.employee.authority == 2}"> --> <td class="button"> <form method="get" th:action="@{/update/input}"> <input type="hidden" name="empId" th:value="${employee.empId}" /> <input type="hidden" name="deptId" th:value="${employee.department.deptId}" /> <input type="submit" value="変更" /> </form> </td> <td class="button"> <form method="get" th:action="@{/delete/check}"> <input type="hidden" name="empId" th:value="${employee.empId}" /> <input type="submit" value="削除" class="delete" /> </form> </td> </th:block> </tr> </table>
コード /** * 社員名検索処理 * @param model * @param empName * @return 一覧画面 */ @RequestMapping(path = "/find", method = RequestMethod.POST) public String find(Model model, String empName) { //▼名前の検索実施 List<Employee> employees = employeeRepository.findByEmpNameLike("%" + empName + "%"); model.addAttribute("employees", employees); return "list/list"; } /** * 部署名検索処理 * @param model * @param deptId * @return 一覧画面 */ @RequestMapping(path = "/findDept", method = RequestMethod.POST) public String find(Model model, int deptId) { //▼部署の検索実施 Department department = new Department(); department.setDeptId(deptId); List<Employee> employees = employeeRepository.findByDepartment(department); model.addAttribute("employees", employees); return "list/list"; }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/07/22 12:17