index.html
<a th:href="'/test1/delete/' + ${list.id}"><button type="button" class="btn btn-danger">削除</button></a>
delete_complete.html
<h1>社員情報削除 完了</h1> <div class="col-md-8"> <p>社員の削除が完了しました。</p> <table class="table"> <tr><td>名前</td><td th:text="${name}"></td></tr> <tr><td>所属</td><td th:text="${department}"></td></tr> </table> <button type="button" class="btn btn-primary" onclick="location.href='/test1/index'">一覧に戻る</button> </div>
UserRepository.java
public Users delete(Long id) throws DataAccessException { String sql1 = "" + "SELECT * FROM users WHERE id = ?"; Map<String, Object> users = jdbcTemplate.queryForMap(sql1, id); Users user = new Users(); user.setName((String)users.get("name")); user.setDepartment((String)users.get("department")); String sql2 = "DELETE FROM users WHERE id = ?"; jdbcTemplate.update(sql2, id); return user; }
MainController.java
@GetMapping("delete/{userId}") public String deleteUser(@PathVariable("userId") long userId, Model model) { Users user = usersRepository.delete(userId); model.addAttribute("name", user.getName()); model.addAttribute("department", user.getDepartment()); return "test1/delete_complete"; }
一度理解するとあとは早いな
とりあえずCRUD完
authに行きたいが、まずこれでVPSにデプロイしてみたい。