java spring でデータを一覧で表示しています
その際 htmlのtableのIDを選択した場合に 降順 昇順で表示を切り替えたいのですが
どの部分で処理を追加すればよいかイメージがつきません。
処理の流れはjspで値をpostしてコントローラーで受け取ってdaoに引継ぐといった
事を考えています。
どなたかご教授いただければと存じます。
jsp
<table class="table table-bordered table-hover"> <tr> <th>id</th> <th>姓</th> <th>名</th> <th>詳細</th> </tr> <c:forEach items="${employees}" var="employee" varStatus="status"> <tr> <th>${employee.id}</th> <th>${employee.familyName}</th> <th>${employee.firstName}</th> <th> <form action="show.do" method="POST"> <input type="hidden" name="id" value="${employee.id}"> <input type="submit" value="詳細"> </form> </th> </tr> </c:forEach> </table>
コントローラー
//データ一覧表示 @RequestMapping(value="/employee/list.do", method=RequestMethod.GET) public ModelAndView showList(){ List<EmployeeModel> list = this.dao.getEmployees(); String name = "examples/list_sample"; return new ModelAndView(name, "employees", list); }
dao
public List<EmployeeModel> getEmployees() { String sql = "SELECT id, family_name,first_name FROM m_employee ORDER BY id DESC"; RowMapper<EmployeeModel> mapper = new BeanPropertyRowMapper<EmployeeModel>(EmployeeModel.class); Object[] args = new Object[] {}; List<EmployeeModel> employeeList = this.jdbcTemplate.query(sql, args, mapper); return employeeList; }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/24 01:22