#22 mvc: add controller - user list
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
32
my-framework/mvc-practice/webapp/user/list.jsp
Normal file
32
my-framework/mvc-practice/webapp/user/list.jsp
Normal 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>
|
||||
Reference in New Issue
Block a user