02H. ROOT URL
Less than 1 minute
02H. ROOT URL ๊ด๋ จ
2-08. ROOT URL
์ ํ ํฌ ์คํ๋ง๋ถํธ - WikiDocs
๋ฃจํธ URL์ http://localhost:8080
์ฒ๋ผ ๋๋ฉ์ธ๋ช
๊ณผ ํฌํธ ๋ค์ ์๋ฌด๊ฒ๋ ๋ถ์ด์ง ์์ URL์ ๋งํ๋ค.

์ด๋ฒ์๋ ๋ฃจํธ URL ํธ์ถ์ 404 ํ์ด์ง ๋์ ์ง๋ฌธ ๋ชฉ๋ก์ ์ถ๋ ฅํ๋๋ก ํด๋ณด์. ๋ค์๊ณผ ๊ฐ์ด MainController
๋ฅผ ์์ ํ์.
package com.mysite.sbb;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MainController {
@GetMapping("/sbb")
@ResponseBody
public String index() {
return "์๋
ํ์ธ์ sbb์ ์ค์ ๊ฒ์ ํ์ํฉ๋๋ค.";
}
@GetMapping("/")
public String root() {
return "redirect:/question/list";
}
}
root ๋ฉ์๋๋ฅผ ์ถ๊ฐํ๊ณ /
URL์ ๋งคํํ๋ค. ๋ฆฌํด ๋ฌธ์์ด redirect:/question/list
๋ /question/list
URL๋ก ํ์ด์ง๋ฅผ ๋ฆฌ๋ค์ด๋ ํธ ํ๋ผ๋ ๋ช
๋ น์ด์ด๋ค. ์คํ๋ง๋ถํธ๋ ๋ฆฌ๋ค์ด๋ ํธ ๋๋ ํฌ์๋ฉ์ ๋ค์๊ณผ ๊ฐ์ด ํ ์ ์๋ค.
redirect:<URL>
: URL๋ก ๋ฆฌ๋ค์ด๋ ํธ (๋ฆฌ๋ค์ด๋ ํธ๋ ์์ ํ ์๋ก์ด URL๋ก ์์ฒญ์ด ๋๋ค.)forward:<URL>
: URL๋ก ํฌ์๋ (ํฌ์๋๋ ๊ธฐ์กด ์์ฒญ ๊ฐ๋ค์ด ์ ์ง๋ ์ํ๋ก URL์ด ์ ํ๋๋ค.)
์ด์ http://localhost:8080
ํ์ด์ง ์ ์์ ํ๋ฉด root ๋ฉ์๋๊ฐ ์คํ๋์ด ์ง๋ฌธ ๋ชฉ๋ก์ด ํ์๋๋ ๊ฒ์ ํ์ธํ ์ ์์ ๊ฒ์ด๋ค.