SpringBoot - DAY 1

NewTypeAsuka·2023년 6월 1일
0

SpringBoot@

목록 보기
3/5

1. SpringBoot

SpringBoot

  • Spring MVC Project 구성 시 필요했던 복잡한 환경 설정을 최소화하여
    개발자로 하여금 비즈니스 로직 구현에 집중할 수 있도록 하기 위하여 개발
  • 장점:
    1) 내장된 서버(Tomcat 등)를 제공해서 war 배포 없이 독립 실행이 가능한 웹애플리케이
    션을 개발할 수 있음
    2) 다양한 Starter POM 파일을 제공해서 Maven, Gradle 등의 빌드 도구 구성, 라이브러
    리 관리를 간소화
    3) Spring Starter를 이용해서 프로젝트를 생성 및 초기설정을 간소화
  • SpringBoot는 업데이트 속도가 매우 빠르기 때문에 버전 관리에 유의한다.

SpringBoot 관련 설정

  • SpringBoot는 jsp 대신 thymeleaf를 사용하기 때문에
    html 파일에 thymeleaf 양식으로 파라미터를 받아서 사용한다.
  • SpringBoot는 따로 서버 설정을 할 필요가 없다.
  • springboot는 기본적으로 모든 dependency를 내장하고 있고
    build.gradle의 dependencies에서 모든 dependency가 on/off 형식으로 작동한다.
  • src/main/resources의 templates가 views 역할을 하고 여기에 html 모아둔다.
@Controller
public class MainController {
	@RequestMapping("/")
	public String mainForward(Model model) {
		model.addAttribute("message", "스프링부트 테스트 중입니다.");
		// Spring MVC의 경우 /webapp/WEB-INF/views/common/main.jsp로 forward
		// SpringBoot의 경우(+thymeleaf 템플릿 엔진 적용 == jsp 대신 사용)
		// src/main/resources/templates/common/main.html로 forward
		return "common/main";
	}
}
<!DOCTYPE html>
<html lang="ko" xmlns="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SpringBoot Test</title>
</head>
<body>
    <h1>메인페이지입니다.</h1>
    <h1 th:text="${message}">여기에 message가 출력될 겁니다.</h1> <!-- 사실상 덮어씌우기 때문에 설명을 적는 것 -->
    <input type="text" th:value="${message}">
    <script th:inline="javascript"> // JS에서 thymeleaf를 사용하기 위한 설정
        const message = /*[[${message}]]*/ "전달 받은 message"; // 사실상 덮어씌우기 때문에 설명을 적는 것
        alert(message);
    </script>
</body>
</html>

  • src/main/java: 자바 소스 코드를 모아두는 폴더
  • src/main/resources: 자바에서 사용할 자원, 설정 파일을 모아두는 폴더
    • templates: Java 템플릿을 모아두는 폴더(thymeleaf)
    • static: templates에 적용될 정적 자원을 모아두는 폴더(JS, CSS, 이미지)
    • application.properties: SpringBoot 프로젝트 관련 설정을 정의하는 파일
  • Project and External Dependencies: build.gradle에 명시된 라이브러리 모음
  • src: jsp 사용 시 자원이 모이는 폴더(Spring MVC 프로젝트를 생각하면됨)
  • build.gradle: gradle(빌드도구 == maven의 pom.xml)
    프로젝트에 필요한 라이브러리, 배포, 빌드 관련 설정을 작성하는 파일

0개의 댓글