Created
May 28, 2025 21:39
-
-
Save benelog/2ef5203d7af40c0492871f886c644f21 to your computer and use it in GitHub Desktop.
Smart UI : Model1 by Spring Boot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Application implements WebMvcConfigurer { | |
public static void main(String[] args) { | |
SpringApplication.run(Application.class, args); | |
} | |
@Override | |
public void addViewControllers(ViewControllerRegistry registry) { | |
registry.addViewController("/repos").setViewName("repos"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> | |
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | |
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%> | |
<%@ page import="org.springframework.jdbc.core.ColumnMapRowMapper"%> | |
<%@ page import="org.springframework.web.context.WebApplicationContext"%> | |
<%@ page import="javax.sql.DataSource"%> | |
<%@ page import="java.util.List"%> | |
<%@ page import="java.util.ArrayList"%> | |
<%@ page import="java.util.Map"%> | |
<%@ page import="java.util.HashMap"%> | |
<%@ page import="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate"%> | |
<c:set var="sql"> | |
SELECT r.name, r.description, a.name AS creator_name , a.email | |
FROM repo r | |
INNER JOIN account a ON a.id = r.created_by | |
WHERE a.email = :email | |
</c:set> | |
<% | |
String email = request.getParameter("email"); | |
String sql = (String) pageContext.getAttribute("sql"); | |
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); | |
DataSource ds = (DataSource) ctx.getBean("dataSource"); | |
NamedParameterJdbcTemplate db = new NamedParameterJdbcTemplate(ds); | |
Map<String, Object> params = Map.of("email", email) | |
List<Map<String,Object>> repos = db.<Map<String,Object>>query(sql, params, new ColumnMapRowMapper()); | |
request.setAttribute("repos", repos); | |
%> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>저장소 조회</title> | |
</head> | |
<body> | |
<h1>저장소를 만든 사람의 이메일로 검색하기</h1> | |
<form action="/files" method="GET"> | |
<h2>이메일 입력</h2> | |
<p> | |
<input type="text" name="email" size="40" value="${email}"> <input type="submit" value="조회"> | |
</p> | |
</form> | |
<h2>조회 결과</h2> | |
<table border="1"> | |
<tr> | |
<th>저장소 이름</th> | |
<th>저장소 설명</th> | |
<th>생성자</th> | |
<th>이메일</th> | |
</tr> | |
<c:forEach var="item" items="${repos}"> | |
<tr> | |
<td>${item.name}</td> | |
<td>${item.description}</td> | |
<td>${item.creator_name}</td> | |
<td>${item.email}</td> | |
</tr> | |
</c:forEach> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment