회원목록 출력하기
by 볼빵빵오춘기Controller
@GetMapping("/")
public String findAll(Model model){
List<MemberDTO> memberDTOList = memberService.findAll();
model.addAttribute("memberList",memberDTOList);
return "list";
}
Service
public List<MemberDTO> findAll() {
return memberRepository.findAll();
}
Repository
public List<MemberDTO> findAll() {
return sql.selectList("Member.findAll");
}
Mapper
<select id="findAll" resultType="member">
select * from member_table
</select>
list.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 추가한다.
why? jstl을 가져왔기때문에 반복문이 필요하다. jsp에서 제공하는 태그이다.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>list</title>
</head>
<body>
<table>
<tr>
<th>id</th>
<th>email</th>
<th>password</th>
<th>name</th>
<th>age</th>
<th>mobile</th>
<th>조회</th>
<th>삭제</th>
</tr>
<c:forEach items="${memberList}" var="member">
<tr>
<td>${member.id}</td>
<td>
<a href="/member?id=${member.id}">${member.memberEmail}</a>
</td>
<td>${member.memberPassword}</td>
<td>${member.memberName}</td>
<td>${member.memberAge}</td>
<td>${member.memberMobile}</td>
<td>
<a href="/member?id=${member.id}">조회</a>
</td>
<td>
<button onclick="deleteMember('${member.id}')">삭제</button>
</td>
</tr>
</c:forEach>
</table>
</body>
<script>
const deleteMember = (id) => {
console.log(id);
location.href = "/member/delete?id="+id;
}
</script>
</html>
'강의 따라하기 > springframework_setting' 카테고리의 다른 글
회원삭제하기 (0) | 2024.10.22 |
---|---|
회원정보 상세조회하기 (0) | 2024.10.22 |
로그인 구현하기 (0) | 2024.10.22 |
회원가입 완성하기 (0) | 2024.10.22 |
회원가입 시작하기 (0) | 2024.10.22 |
블로그의 정보
Hello 춘기's world
볼빵빵오춘기