https://start.spring.io/
추세) 스프링 프로젝트를 대부분 스프링 부트를 기반으로 생성
External Library에 여러 라이브러리 있음 > 여기서 사용중인 라이브러리확인 가능
<!DOCTYPE HTML>
<html>
<head>
<title>hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<a href="/hello">hello</a>
</body>
</html>
https://docs.spring.io/spring-boot/docs/2.6.7/reference/htmlsingle/#web
hello.hellospring/controller/HelloController.java
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
@GetMapping
public String hello(Model model){
model.addAttribute("data", "hello");
return "hello";
}
}
resources/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>
cmd 이용해서 실행 가능 (IntelliJ 말고)
본 포스트는 김영하의 <스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술> 강좌를 바탕으로 작성한 포스트입니다.