[인프런_스프링입문]섹션 1. 프로젝트 환경설정

이도은·2021년 11월 4일
0

스프링입문

목록 보기
1/4
post-thumbnail

라이브러리 살펴보기

Gradle은 의존관계가 있는 라이브러리를 함께 다운로드 한다.

스프링 부트 라이브러리

ㆍspring-boot-starter-web
	ㆍspring-boot-starter-tomcat: 톰캠(웹서버)
	ㆍspring-web-mvc: 스프링 웹 MVC    
ㆍspring-boot-starter-thymeleaf: 타임리프 템플릿 엔진(View)
ㆍspring-boot-starter(공통): 스프링 부트 + 스프링 코어 + 로깅
	ㆍspring-boot
		ㆍspring-core
    ㆍspring-boot_starter-logging
		ㆍlogback, slf4j
        

테스트 라이브러리

ㆍspirng-boot-starater-test
	ㆍjunit: 테스트 프레임워크
	ㆍmockito: 목 라이브러리
	ㆍassertj: 테스트 코드를 좀 더 편하게 작성하게 도와주는 라이브러리
    ㆍspring-test: 스프링 통합 테스트 지원



View 환경설정

Welcome Page 만들기

resource/static/index.html

<!DOCTYPE HTML>
<html>
<head>
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello
<a herf="/hello">hello</a>
</body>
</html>
@Controller
public class HelloController {

    @GetMapping("hello")
    public String hello(Model model){
        model.addAttribute("data", "hello!!");
        return "hello";
    }
}

resource/templates/hello.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p th:text="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p>
</body>
</html>

thymeleaf 템플릿엔진 동작 확인
ㆍ실행: http://localhost:8080/hello

ㆍ컨트롤러에서 리턴 값으로 문자를 반환하면 뷰 리졸버(viewResolver)가 화면을 찾아서 처린한다.
ㆍ스프링 부트 템플릿엔진 기본 viewName 매핑
ㆍresources:templates/ + {ViewName} + .html




빌드하고 실행하기




참고자료: 인프런 스프링입문 김영한님 강의노트

0개의 댓글