Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- data
- activity
- livedata
- tabbar
- LifeCycle
- 앱
- 앱바
- Kotlin
- drift
- ScrollView
- appbar
- 안드로이드
- viewmodel
- android
- Button
- Navigation
- DART
- intent
- Compose
- Dialog
- binding
- Flutter
- 계측
- TEST
- textview
- textfield
- Coroutines
- scroll
- CustomScrollView
- 테스트
Archives
- Today
- Total
Study Record
[Spring] Welcome Page, GetMaping 본문
728x90
✍ Welcome Page
서버를 실행하고 http://localhost:8080 으로 접속했을 때 기본적으로 보이는 페이지를 설정할 수 있다. resources/static 디렉터리에 index.html 파일을 만들면 이 페이지가 기본 페이지가 된다.
✍ GetMaping 이용하기
① 먼저, 컨트롤러 자바 파일을 하나 생성한다.
@Controller
public class HelloController {
@GetMapping("hello1")
public String hello(Model model){
model.addAttribute("data", "Hello");
return "hello";
}
}
② resources/templates 파일안에 hello.html 파일을 생성한다.
코드 해석을 해보면, HelloController 에서 GetMapping("hello1") 은 http://localhost:8080/hello1 으로 접속했을 때 HelloController 의 hello 함수가 실행된다는 의미이다. GetMapping 값을 "rest" 로 바꾼다면 httlp://localhost:8080/rest 로 접속해야 한다.
HelloController 의 return 값은 resources:templates/{return 값}.html 에 매핑된다. 따라서 뷰 리졸버(ViewResolver) 가 매핑된 화면인 hello.html 파일을 찾아 처리한다.
HelloController 의 model("data", "Hello") 는 매핑되는 화면인 hello.html 의 data 변수(8번째 줄의 ${data})의 값에 "Hello"를 대신 넣겠다는 의미이다.
따라서, http://localhost:8080/hello1 으로 접속해보면 다음과 같은 결과를 얻을 수 있다.
728x90
'Spring' 카테고리의 다른 글
[Spring] 기본 정리 (0) | 2022.06.05 |
---|---|
[Spring] 웹 개발 기초 (0) | 2022.06.05 |
[Spring] 빌드하기 (0) | 2022.06.05 |
[Spring] 프로젝트 생성하기 (0) | 2022.06.05 |