Spring(기초)-2021.12.08

Jonguk Kim·2021년 12월 9일
0

Spring 기초

목록 보기
1/5

1. Welcome Page

  1. http://localhost:8080/ 요청
  2. static 폴더에서 index 파일 찾음 ( static/index.html )
  3. static 폴더에 없으면 templates 폴더에서 index 파일 찾음 ( templates/index.html )

2. thymeleaf 템플릿 엔진

@Controller
public class HelloController {
	@GetMapping("hello")
	public String hello(Model model) {
   		model.addAttribute("data", "hello!!"); // thymeleaf 에 data 변수명으로 값 전달
		return "hello"; // templates/hello.html
        }
}

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

3. 빌드하고 실행하기

  1. 해당 프로젝트 경로로 이동
  2. ./gradlew build
  3. cd build/libs
  4. java -jar hello-spring-0.0.1-SNAPSHOT.jar
  5. 실행확인
profile
Just Do It

0개의 댓글