< application.yml >
server:
port: 8000
servlet:
context-path: /blog
encoding:
charset: UTF-8
enabled: true
force: true
spring:
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3307/blog?serverTimezone=Asia/Seoul
username: yj
password: yj0118
jpa:
open-in-view: true
hibernate:
ddl-auto: create
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
use-new-id-generator-mappings: false
show-sql: true
properties:
hibernate.format_sql: true
jackson:
serialization:
fail-on-empty-beans: false
server:
port: 8080
servlet:
context-path: /
์๋๋ ์์ฒ๋ผ ํฌํธ 8080์ ๋ฐ๋ก ์ปจํ
์คํธ ํจ์ค๋ฅผ ์ ํด์ฃผ์ง ์์ ๊ทธ๋ฅ / ๋ก ์ฌ์ฉํ๋ค.
์๋ฅผ ๋ค๋ฉด "localhost:8080/http/test" ์ฒ๋ผ ์ฌ์ฉํ ๊ฒ์ด๋ค.
server:
port: 8000
servlet:
context-path: /blog
๋ณ๊ฒฝํ์ฌ์ ์ด๋ ๊ฒ ์ง์ ํ๊ฒ ๋๋ฉด "localhost:8000/blog/http/test" ์ฒ๋ผ ์ฌ์ฉํ๊ฒ ๋๋ค.
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3307/blog?serverTimezone=Asia/Seoul
username: yj
password: yj0118
์ด์ ์ ์ค์ ํ๋ ๊ฒ ๊ทธ๋๋ก!! ์ฌ๊ธฐ
@Controller // ๋ฐ์ดํฐ ๋ฆฌํด(Json ๋ฑ)์ด ์๋ "ํ์ผ" ๋ฆฌํด (<-> @RestController ๋์ ๋ค๋ฆ)
public class TempControllerTest {
// http://localhost:8000/blog/temp/home
@GetMapping("/temp/home")
public String tempHome() {
System.out.println("tempHome()");
// ํ์ผ๋ฆฌํด ๊ธฐ๋ณธ๊ฒฝ๋ก : src/main/resources/static ์ธ๋ฐ
// return "home.html"; ๋ผ๊ณ ํ๋ฉด
// ํ์ผ๋ฆฌํด ํ๊ฒฝ๋ก : src/main/resources/statichome.html ์ด ๋๋ ๊ฒ์ด๋ค.
// ๋ฐ๋ผ์ ํ์ผ๋ฆฌํด ๊ธฐ๋ณธ ๊ฒฝ๋ก์ ๋ฆฌํด๋ช
์ /home.html ๋ก ํ๋ฉด
// ํ์ผ๋ฆฌํด ํ๊ฒฝ๋ก : src/main/resources/static/home.html
return "/home.html";
}
}
์์๋ ํ
ํ๋ฆฟ ์์ง์ html์ ์ผ์ง๋ง, jsp๋ฅผ ์ฐ๊ณ ์ถ๋ค๋ฉด?
-> ์คํ๋ง๋ถํธ๋ jsp๋ฅผ ์ง์ํ์ง ์๋๋ค. ์ฆ, jsp๋ฅผ ๋ฆฌํดํด๋ ์ ์๋์ํ์ง ์๋๋ค.
static ์๋๋ ์ ์ ํ์ผ์ด ์์ด์ผ ์ฐพ์ ์ ์๋๋ฐ, jsp๋ ์ ์ ํ์ผ์ด ์๋๋ค. ๋์ ํ์ผ์ด๋ค.
๋ฐ๋ผ์ ํ์ํ ๊ฒ!
< pom.xml >
<!-- JSP ํ
ํ๋ฆฟ ์์ง -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
< application.yml >
spring:
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
prefix๋ ์ปจํธ๋กค๋ฌ๊ฐ ๋ฆฌํดํ ๋ ์์ ๋ถ์ฌ์ฃผ๋ ๊ฒฝ๋ก๋ช
์ด๊ณ , suffix๋ ๋ค์ ๋ถ์ฌ์ฃผ๋ ๊ฒฝ๋ก๋ช
์ด๋ค.
๋ฐ๋ผ์ src/main/webapp/WEB-INF/views ๋๋ ํ ๋ฆฌ๋ฅผ ์ง์ ๋ง๋ค์ด์ผ ํ๋ค.
@GetMapping("/temp/jsp")
public String tempJsp() {
// prefix: /WEB-INF/views/
// suffix: .jsp
// return "/test.jsp";
// ํ๊ฒฝ๋ก๋ /WEB-INF/views//test.jsp.jsp ์ด ๋๋ค.
// ํ์ง๋ง return "test"; ๋ก ํ๋ค๋ฉด
// ํ๊ฒฝ๋ก๋ /WEB-INF/views/test.jsp ์ด ๋์ด ์ฐพ์์ง๊ฒ ๋๋ค.
return "test";
}
์ด๋ฏธ ๋ค์ ํ์ฅ์๋ช ์ ์ค์ ํ์ผ๋ก ์ถ๊ฐํ์ผ๋ฏ๋ก, return์๋ ์์ฒ๋ผ ํ์ผ์ด๋ฆ ๋ง์ ์์ฑํด์ผ ํ๋ค.
์ ๋ฆฌํ์๋ฉด, !!!
๐ก ํฐ์บฃ(์์ฒญํ ํ์ผ ์ค ์๋ฐ ํ์ผ์ด ์์ผ๋ฉด ์ปดํ์ผ ํ์ฌ htmlํ์ผ๋ก ๋ฒ์ญํด์ ์๋ตํ๋ ์น๊ตฌ) :
์ด? jsp ํ์ผ์ด๋ค? ๊ทธ๋ฌ๋๊น java ํ์ผ์ด๊ตฌ๋!
์น ์๋ฒ์ ์ํ์น(์ ์ ํ์ผ ์๋ตํ๋ ์น๊ตฌ)์ผ! ์ด๊ฑด ๋๊ฐ ํ ์ ์๋ ์ผ์ด ์๋๋๊น ํฐ์บฃ์ธ ๋ด๊ฐ ์ด ํ์ผ์ ์ปดํ์ผ ํด์ htmlํ์ผ๋ก ์๋ตํ ๊ฒ. ๊ทธ๋ผ ์น ๋ธ๋ผ์ฐ์ ๊ฐ ์ดํดํ ์ ์์๊ฑฐ์ผ!