Notice
Recent Posts
Recent Comments
Link
«   2024/04   »
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 29 30
Archives
Today
Total
관리 메뉴

공부하자

[Spring Boot] 2. Spring Starter 프로젝트 생성 본문

공부/Spring Boot

[Spring Boot] 2. Spring Starter 프로젝트 생성

strongstar 2017. 11. 7. 22:57

* 참고 도서 : 쇼다 츠야노 (2017). 스프링 부트 프로그래밍 입문. 길벗

* 가급적 자주, 적어도 일주일에 한번 이상은 포스팅하려고 합니다.

* 이전 포스팅 : [Spring Boot] 1. Maven 프로젝트 생성



1. Spring Starter Project 생성


File - New - Spring Starter Project 를 클릭합니다.



위와 같이 입력하고 Next.



Hello World 만 찍고 끝낼거니까 web 만 체크해주고 Finish 합니다.



폴더 구조가 이렇습니다.



2. Controller 생성



src\main\java\com\star\springboot 아래에 Controller를 생성할 겁니다.



ctrl + n 단축키로 생성할 수도 있습니다.



Name 입력하고 Finish.



3. index 페이지 생성



templates에 html 파일을 생성합니다.



File name 입력하고 Next.



html 5 로 두고 Finish. 



그러면 최종적으로는 이렇게 됩니다.



4. 파일 수정하기


- pom.xml


1
2
3
4
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
cs


- TestController.java


1
2
3
4
5
6
7
8
9
10
11
12
13
package com.star.springboot;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
 
@Controller
public class TestController {
    
    @RequestMapping("/")
    public String index() {
        return "index";
    }
}
cs


- index.html


1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title</title>
</head>
<body>
    <h1>Hello World</h1>
 
</body>
</html>
cs


pom.xml에 dependency 추가해주고, Controller, index는 위와 같이 변경합니다.



5. 실행



프로젝트에서 마우스 우클릭 - Run As - Spring Boot App 클릭.



상단 아이콘으로도 실행시킬 수 있습니다.



그러면 서버가 실행되고..



http://localhost:8080/ 으로 접속하면 Hello World 라고 뜹니다!!




스프링 부트는 기본적으로 자바 서버가 내장되어 있습니다.

따라서 클라우드 서비스에서 기존 스프링 보다 스프링 부트가 유리합니다.

타임리프 템플릿 엔진을 사용합니다.

Comments