[스프링 입문] 스프링 동작 구조, 터미널에서 서버 띄우기

강신현·2022년 7월 29일
0

스프링 동작 구조

  • HelloController
@Controller
public class HelloController {

    @GetMapping("hello")
    public String hello(Model model){
        model.addAttribute("data", "hello!!");
        return "hello";
    }
}
  • 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>

  1. 컨트롤러에서 리턴 값으로 문자를 반환
  2. 뷰 리졸버( viewResolver )가 화면을 찾아서 처리
    👉 resources:templates/ +{ViewName}+ .html
    여기서 ViewName은 hello

터미널에서 서버 띄우기

  1. 프로젝트 디렉토리로 이동 (hello-spring)
  2. 빌드 (실행파일 생성)

  1. build/lib 디럭터리로 이동
  2. java (.jar) 파일 실행

  • 잘안될 경우 build 파일 지우고 다시 빌드 ./gradlew clean build

강의 출처

[인프런 - 김영한] 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술

profile
땅콩의 모험 (server)

0개의 댓글