#22 mvc: add controller - user list

This commit is contained in:
haerong22
2022-10-11 00:29:14 +09:00
parent 99f0b69f42
commit a235f0f396
3 changed files with 47 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package org.example.mvc;
import org.example.mvc.controller.Controller;
import org.example.mvc.controller.HomeController;
import org.example.mvc.controller.UserListController;
import java.util.HashMap;
import java.util.Map;
@@ -12,6 +13,7 @@ public class RequestMappingHandlerMapping {
void init() {
mappings.put("/", new HomeController());
mappings.put("/users", new UserListController());
}
public Controller findHandler(String uriPath) {

View File

@@ -0,0 +1,13 @@
package org.example.mvc.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
public class UserListController implements Controller {
@Override
public String handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setAttribute("users", List.of());
return "/user/list.jsp";
}
}

View File

@@ -0,0 +1,32 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="kr">
<head>
<meta charset="UTF-8">
<title>list</title>
</head>
<body>
<table>
<thead>
<tr>
<th>#</th>
<th>아이디</th>
<th>이름</th>
<th></th>
</tr>
</thead>
<tbody>
<c:forEach items="${users}" var="user" varStatus="status">
<tr>
<th scope="row">${status.count}</th>
<td>${user.userId}</td>
<td>${user.name}</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>