아래와 같이 설정 후, Generate
groupId: 프로젝트를 정의하는 고유한 식별자 정보
artifactId: 버전 없는 Jar 파일 이름
IntelliJ에서 generate한 파일들 중 build.gradle open (as project)
src/main/java/<group이름>.<이름> 클래스의 main method 실행
localhost:8080에 접속하였을 때, 에러 페이지가 뜨면 성공!
src/main/resources/static에 index.html 만들기
<!DOCTYPE HTML>
<html>
<head>
<title>Main</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
안녕하세요. <br>
<a href="/login">로그인</a>
</body>
</html>
package lgcns.internproject.controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.stereotype.Controller;
@Controller
public class LoginController {
@GetMapping("login")
public String login(Model model) {
model.addAttribute("data", "로그인 되었습니다:)");
return "login";
}
}
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p>
</body>
</html>
th→ thymeleaf
${data} → controller에서의 attribute value
[결과]
cd {스프링 부트 프로젝트가 위치한 폴더}
./gradlew build
cd build/libs
ls-arlth
java -jar {project name}-0.0.1-SNAPSHOT.jar
*잘 안될 경우
cd {스프링 부트 프로젝트가 위치한 폴더}
./gradlew clean build
[참고][https://www.inflearn.com/course/스프링-입문-스프링부트/dashboard](https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%EC%9E%85%EB%AC%B8-%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8/dashboard)