Home 섹션1. 프로젝트 환경설정
Post
Cancel

섹션1. 프로젝트 환경설정

스프링 부트 스타터 사이트 start.spring.io

  • Maven → 과거
  • Gradle → 최근
  • Spring Web
  • Thymeleaf → 템플릿 엔진

프로젝트 내

  • build.gradle
    • dependencies → 스타터 사이트에서 추가했던 dependencies 라이브러리들 집합
    • repositories{ mavenCentral() } → 라이브러리들 다운받는 공개된 사이트
  • gitignore
    • git에 올라가면 안되는 파일 설정

핵심 라이브러리

스프링 부트 라이브러리

  • spring-boot-starter-web
    • spring-boot-starter-tomcat → 내장 웹서버
    • spring-webmvc → 스프링 웹 mvc
  • spring-boot-starter-thymeleaf → 타임리프 템플릿 엔진
  • spring-boot-starter
    • spring-boot
      • spring-core
    • spring-boot-starter-logging
      • logback, slf4j

테스트 라이브러리

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

View

HelloController.java

1
2
3
4
5
6
7
8
9
10
@Controller // 컨트롤러임을 선언
public class HelloController {

    @GetMapping("hello") // http://localhost:8080/hello로 접속 시 캐치
    public String hello(Model model){
	      model.addAttribute("data","hello!!"); //값을 model에 담아서 넘겨준다. 값의 key는 "data", value는 "hello!!"다.
        return "hello"; // hello.html에 model을 넘겨줌
    }

}

hello.html

1
2
3
4
5
6
7
8
9
10
11
<!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> <!--helloController에서 보낸 model의 data -->
</body>
</html>

프로젝트 build 후 실행

  1. ./gradlew build → 프로젝트 build
  2. build/libs로 이동
  3. java -jar “프로젝트 jar파일” → 실행
This post is licensed under CC BY 4.0 by the author.