๐ก์์ ์์
1. mainController.java ํ์ผ ์์ฑ
2. ๊ฐ๋จํ CSS ์ค์ ํ๊ธฐ
3. ์ธ๋ถ ์คํ์ผ ์ํธ๋ก ๋ณ๊ฒฝ ํ๊ธฐ
4. ํ๋จ์ ๋ถ๋ ํธํฐ ์ค์ ํ๊ธฐ (๊ฐ์ด๋ฐ ์ปจํ ์ธ ๊ฐ ์์ผ๋ฉด ํธํฐ๊ฐ ์ค๊ฐ์ผ๋ก ์ฌ๋ผ ์ด)
๋ฒ๊ทธ ํ์ธ
// TODO - tools xml ํ์ผ error check
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
1. mainController.java ํ์ผ ์์ฑ
package com.tenco.bank.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller // IoC ๋์(์ฑ๊ธํค ํจํด ๊ด๋ฆฌ๊ฐ ๋๋ค.) --> ์ ์ด์ ์ญ์
public class MainController {
// REST API ๊ธฐ๋ฐ์ผ๋ก ์ฃผ์์ค๊ณ ๊ฐ๋ฅ
// ์ฃผ์์ค๊ณ
// http:localhost:8080/main-page
@GetMapping({"/main-page", "/index"})
public String mainPage() {
System.out.println("mainPage() ํธ์ถ ํ์ธ");
// [JSP ํ์ผ ์ฐพ๊ธฐ (yml ์ค์ ) ] - ๋ทฐ ๋ฆฌ์กธ๋ฒ
// prefix: /WEB-INF/view
// /main
// suffix: .js
return "/main";
}
}
์ด๋ฏธ์ง ํ์ฉ - ๋งํฌ ์ฒ๋ฆฌ
https://picsum.photos/id/1/350
2. ๊ฐ๋จํ CSS ์ค์ ํ๊ธฐ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>myBank</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
<style>
.m--banner-img {
background-image: url(https://picsum.photos/600);
background-size: cover;
background-position: center;
width: 100%;
}
.m--profile {
background-image: url(https://picsum.photos/id/1/350);
width: 100%;
height: 200px;
background-size: cover;
background-position: center;
}
</style>
</head>
<body>
<div class="jumbotron text-center m--banner-img" style="margin-bottom:0">
<h1>My Bank</h1>
<p>๋ง์ด๋ฐ์ดํฐ์ค๋ฅผ ํ์ฉํ ์คํ๋ง ๋ถํธ ์ฑ ๋ง๋ค์ด๋ณด๊ธฐ</p>
</div>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
<div class="container" style="margin-top:30px">
<div class="row">
<div class="col-sm-4">
<h2>About Me</h2>
<h5>Photo of me:</h5>
<div class="m--profile"></div>
<p>์ฝ๋ฆฐ์ด ๊ฐ๋ฐ์ ์ํ ๋ฑ
ํฌ ์ฑ</p>
<h3>Some Links</h3>
<p>Lorem ipsum dolor sit ame.</p>
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<hr class="d-sm-none">
</div>
<!-- end of header.jsp -->
3. ์ธ๋ถ ์คํ์ผ ์ํธ๋ก ๋ณ๊ฒฝ ํ๊ธฐ
@charset "UTF-8";
.m--banner-img {
background-image: url(https://picsum.photos/600);
background-size: cover;
background-position: center;
width: 100%;
}
.m--profile {
background-image: url(https://picsum.photos/id/1/350);
width: 100%;
height: 200px;
background-size: cover;
background-position: center;
}
header.jsp - ์ธ๋ถ ์คํ์ผ ์ํธ ์ฐ๊ฒฐ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>myBank</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="jumbotron text-center m--banner-img" style="margin-bottom:0">
<h1>My Bank</h1>
<p>๋ง์ด๋ฐ์ดํฐ์ค๋ฅผ ํ์ฉํ ์คํ๋ง ๋ถํธ ์ฑ ๋ง๋ค์ด๋ณด๊ธฐ</p>
</div>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
<div class="container" style="margin-top:30px">
<div class="row">
<div class="col-sm-4">
<h2>About Me</h2>
<h5>Photo of me:</h5>
<div class="m--profile"></div>
<p>์ฝ๋ฆฐ์ด ๊ฐ๋ฐ์ ์ํ ๋ฑ
ํฌ ์ฑ</p>
<h3>Some Links</h3>
<p>Lorem ipsum dolor sit ame.</p>
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<hr class="d-sm-none">
</div>
<!-- end of header.jsp -->
๐ก ํ๋จ์ ๊ณ ์ ๋๋ ํธํฐ(Footer)๋ฅผ ๋ง๋ค๊ธฐ ์ํด CSS์ Flexbox ๋ ์ด์์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ด๋ฅผ ์ํด์๋ HTML ๊ตฌ์กฐ์ ๋ช ๊ฐ์ง ์กฐ์ ์ ํด์ฃผ๊ณ , ์ ์ ํ CSS ์คํ์ผ์ ์ ์ฉํด์ผ ํฉ๋๋ค.
ํ๋จ์ ๋ถ๋ ํธํฐ ์ค์ ํ๊ธฐ
index.html ํ์ผ์ ์ฐ์ต
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 4 Website Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
<script
src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
<style>
body{
height: 100vh;
margin: 0;
}
.m--flex-container {
display: flex;
flex-direction: column;
height: 100%;
}
.m--container {
flex: 1;
}
</style>
</head>
<body>
<div class="m--flex-container">
<div class="m--container">
<div class="jumbotron text-center" style="margin-bottom: 0">
<h1>My First Bootstrap 4 Page</h1>
<p>Resize this responsive page to see the effect!</p>
</div>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
</ul>
</div>
</nav>
<div class="container" style="margin-top: 30px">
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-8">
<h2>TITLE HEADING</h2>
</div>
</div>
</div>
</div>
<div class="jumbotron text-center" style="margin-bottom: 0">
<p>Footer</p>
</div>
</div>
</body>
</html>
์ค์ ๋ก ์ฌ์ฉํ header.jsp, footer.jsp, common.css ํ์ผ ์์
@charset "UTF-8";
body{
height: 100vh;
margin: 0;
}
.m--flex-container {
display: flex;
flex-direction: column;
height: 100%;
}
.m--container {
flex: 1;
}
.m--banner-img {
background-image: url(https://picsum.photos/600);
background-size: cover;
background-position: center;
width: 100%;
}
.m--profile {
background-image: url(https://picsum.photos/id/1/350);
width: 100%;
height: 200px;
background-size: cover;
background-position: center;
}
header.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>myBank</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="m--flex-container">
<div class="m--container">
<div class="jumbotron text-center m--banner-img" style="margin-bottom: 0">
<h1>My Bank</h1>
<p>๋ง์ด๋ฐ์ดํฐ์ค๋ฅผ ํ์ฉํ ์คํ๋ง ๋ถํธ ์ฑ ๋ง๋ค์ด๋ณด๊ธฐ</p>
</div>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
</ul>
</div>
</nav>
<div class="container" style="margin-top: 30px">
<div class="row">
<div class="col-sm-4">
<h2>About Me</h2>
<h5>Photo of me:</h5>
<div class="m--profile"></div>
<p>์ฝ๋ฆฐ์ด ๊ฐ๋ฐ์ ์ํ ๋ฑ
ํฌ ์ฑ</p>
<h3>Some Links</h3>
<p>Lorem ipsum dolor sit ame.</p>
<ul class="nav nav-pills flex-column">
<li class="nav-item"><a class="nav-link active" href="#">Active</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
<li class="nav-item"><a class="nav-link disabled" href="#">Disabled</a></li>
</ul>
<hr class="d-sm-none">
</div>
<!-- end of header.jsp -->
footer.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- start of footer.jsp -->
<div class="jumbotron text-center" style="margin-bottom: 0">
<p>Footer</p>
</div>
</div>
</div>
</body>
</html>
<!-- end of footer.jsp -->
ํ๋ก์ฐ ์ฐจํธ๋ก ์์ ๋ณด๋ ๊ฐ๋จํ ๋์ ์๋ฆฌ
์คํ๋ง ๋ถํธ ๊ธฐ๋ฐ์ ์น ์ ํ๋ฆฌ์ผ์ด์ ์ด ํด๋ผ์ด์ธํธ(์น ๋ธ๋ผ์ฐ์ )๋ก๋ถํฐ ์์ฒญ์ ๋ฐ์ ์ฒ๋ฆฌํ๋ ์ฃผ์ ๋จ๊ณ์ ํ๋ก์ฐ ์ฐจํธ( ๊ธฐ๋ณธ์ ์ธ ์น ์์ฒญ ๋ฐ ์๋ต ํ๋ก์ธ์ค)
๐ก ์ํ์น์ ํฐ์บฃ
1. ์ ์ ํ์ผ ์์ฒญ์ ๊ฐ๋จํ ์คํ ํ๋ฆ (์: CSS, JS, HTML ์ด๋ฏธ์ง ํ์ผ) - URL ํธ์ถ
- ์น ๋ธ๋ผ์ฐ์ ๊ฐ html, css, js, ์ด๋ฏธ์ง ํ์ผ๊ณผ ๊ฐ์ ์ ์ ํ์ผ์ ์์ฒญํ๋ฉด HTTP ์์ฒญ์ด ์คํ๋ง ๋ถํธ ๋ด์ฅ ์น ์๋ฒ๋ก ์ ์ก๋ฉ๋๋ค.
- ์คํ๋ง ๋ถํธ ๋ด์ฅ ์น ์๋ฒ๋ ํด๋น ์ ์ ํ์ผ์ ์ฐพ๊ณ , ์์ฒญ์ ๋ฐ๋ฅธ ์ ์ ํ์ผ์ ํด๋ผ์ด์ธํธ์ธ ์น ๋ธ๋ผ์ฐ์ ๋ก ์ง์ ์๋ตํฉ๋๋ค.
2. ๋์ ํ์ผ(JSP, JSON …) ์์ฒญ์ ๊ฐ๋จํ ์คํ ํ๋ฆ (์: JSP, json) - ๊ฑฐ์ ๋๋ถ๋ถ URI ํธ์ถ
- ์น ๋ธ๋ผ์ฐ์ ์์ HTTP ์์ฒญ(์: ์น ํ์ด์ง ๋ก๋)์ ์์ฑํ๊ณ , ์ด ์์ฒญ์ ์น ์๋ฒ๋ก ์ ์ก๋ฉ๋๋ค.
- ์น ์๋ฒ๋ ์์ฒญ์ WAS(์น ์ ํ๋ฆฌ์ผ์ด์ ์๋ฒ)๋ก ์ ๋ฌํฉ๋๋ค. WAS๋ ๋์ ์์ฒญ์ ์ฒ๋ฆฌํ ์ ์๋ ์ปจํ ์ด๋(์: Tomcat)๋ก ์๊ฐํ ์ ์์ต๋๋ค.
- ์ปจํ ์ด๋๋ ์คํ๋ง ์ปจํธ๋กค๋ฌ๋ก ์์ฒญ์ ์ ๋ฌํฉ๋๋ค.
- ์คํ๋ง ์ปจํธ๋กค๋ฌ๋ ๋น์ฆ๋์ค ๋ก์ง์ ์ํํ๊ธฐ ์ํด ํ์ํ ์๋น์ค๋ฅผ ํธ์ถํ๊ฑฐ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ํธ ์์ฉํฉ๋๋ค.
- ๋น์ฆ๋์ค ๋ก์ง์ด ์๋ฃ๋๋ฉด, ์ปจํธ๋กค๋ฌ๋ HTML ๋๋ JSON๊ณผ ๊ฐ์ ์๋ต ๋ฐ์ดํฐ๋ฅผ ์์ฑํฉ๋๋ค.
- ์ปจํ ์ด๋๋ ์์ฑ๋ ์๋ต์ ์น ์๋ฒ๋ก ๋ฐํํฉ๋๋ค.
- ์น ์๋ฒ๋ ์น ๋ธ๋ผ์ฐ์ ๋ก ์๋ต์ ์ ์กํ๊ณ , ๋ธ๋ผ์ฐ์ ๋ ๊ฒฐ๊ณผ๋ฅผ ํ์ํฉ๋๋ค.
๐ก์๋ธ๋ฆฟ ์ปจํ ์ด๋๋?
์๋ธ๋ฆฟ ์ปจํ ์ด๋๋ ๊ฐ๋ฐ์๊ฐ ์น ์๋ฒ์ ํต์ ํ๊ธฐ ์ํ์ฌ ์์ผ์ ์์ฑํ๊ณ , ํน์ ํฌํธ์ ๋ฆฌ์ค๋ํ๊ณ , ์คํธ๋ฆผ์ ์์ฑํ๋ ๋ฑ์ ๋ณต์กํ ์ผ๋ค์ ํ ํ์๊ฐ ์๊ฒ ํด์ค๋ค. ์๋ธ๋ฆฟ ์ปจํ ์ด๋๋ servlet์ ์์ฑ๋ถํฐ ์๋ฉธ๊น์ง์ ์ผ๋ จ์ ๊ณผ์ (life-cycle)์ ๊ด๋ฆฌํ๊ณ , ๋งค๋ฒ ์์ฒญ์ด ๋ค์ด์ฌ ๋๋ง๋ค ์๋ก์ด ์ฐ๋ ๋๋ฅผ ์์ฒญ ๋ณ๋ก ๋ถ์ฌํ๋ค.
์์ฝํ๋ฉด, ์๋ธ๋ฆฟ ์ปจํ ์ด๋๋ ํด๋ผ์ด์ธํธ์ HTTP ์์ฒญ์ ๋ฐ์๋ค์ด๊ณ ์๋ธ๋ฆฟ ๋ฐ JSP๋ฅผ ์คํํ๋ ํ๊ฒฝ์ ์ ๊ณตํ๋ ์ํํธ์จ์ด์ ๋๋ค.
'Spring boot' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Spring boot] POST ๋ฐฉ์์ ์ดํด ๋ฐ ์ค์ต (1) | 2024.09.26 |
---|---|
[Spring boot] GET ๋ฐฉ์๊ณผ URL ์ฃผ์ ์ค๊ณ (1) | 2024.09.26 |
[Spring Boot] Bank App (8) - ํ๋ฉด ๊ตฌํ _2(๋ ์ด์์ ๋ถ๋ฆฌ) (0) | 2024.08.14 |
[Spring Boot] Bank App (7) - ํ๋ฉด ๊ตฌํ _1(ํ ํ๋ฆฟ ๊ฐ์ ธ์ค๊ธฐ) (0) | 2024.08.13 |
[Spring Boot] Bank App (6) - ๋ชจ๋ธ๋ง (0) | 2024.08.13 |