inblog logo
|
하쎄의 기술 일기장
    springboot

    [IntelliJ]에서 [Spring] 적용하기 (2)

    2. mustache 연결
    하세연's avatar
    하세연
    Aug 14, 2024
    [IntelliJ]에서 [Spring]  적용하기 (2)
    Contents
    1. resources → static 폴더에 파일 4개 추가하기2. 앞의 파일 4개를 templates로 복사한다— 코드 컨벤션 주의사항

    1. resources → static 폴더에 파일 4개 추가하기

     
    notion image
     
    • 이후 인터넷에서 localhost:8080/ 방금 넣은 파일명을 입력해서 확인해본다(localhost 는 루프백 주소이다)
    ex) localhost:8080/detail (확장자명은 생략해도 된다)
    notion image
    notion image
    notion image
    notion image
    💡
    static 폴더에 넣으면 위치와 상관없이 localhost:8080/폴더명 을 입력하면 찾을 수 있다
    💡
    Web Application Server (아파치 / 톰캣) WAS
    아파치 : 정적 파일만 가능(웹 서버) → 브라우저가 읽을 수 있는 파일 / .html .mp4 .avi .png
    톰캣 : 아파치가 인식 못하는 파일을 위임 받아 식별함 / .java 파일을 받아 컴파일 시킴
    .jsp 는 템플릿 엔진 파일
    (템플릿 엔진 → 정적인 부분은 html로 놔두고, 동적인 부분은 java로 작성)
     

    2. 앞의 파일 4개를 templates로 복사한다

    notion image
     
    • static는 정적 파일 / templates 는 동적 파일이다
    notion image
     
    • mustache의 편의성을 도와주는 프로그램을 다음과 같이 추가한다
    notion image
     
    • 설치 이후 mustache의 파일 아이콘이 바뀌었고, 이를 board 디렉토리를 만들어서 넣어준다.
    notion image
    💡
    이때, 다른 파일들이 없다면 templates.board 로 하나로 합쳐지는데, 이를 방지하기 위해 .keep 파일을 하나 만들어 준다.
    notion image
    package shop.mtcoding.blog.board; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller // 식별자 요청을 받을 수 있다. public class BoardController { // get, post @GetMapping("/board") public String list() { return "board/list"; } // 1. 메서드 : Get // 2. 주소 : /board/1 // 3. 응답 : board/detail @GetMapping("/board/1") public String detail() { return "board/detail"; } // 1. 메서드 : Get // 2. 주소 : /board/save-form // 3. 응답 : board/save-form @GetMapping("/board/save-form") public String saveForm() { return "board/save-form"; } // 1. 메서드 : Get // 2. 주소 : /board/update-form // 3. 응답 : board/update-form @GetMapping("/board/update-form") public String updateForm() { return "board/update-form"; } }
     
    💡
    java 파일에서 board 폴더에 BoardController를 만들어 url에서 주소를 식별할 수 있도록 만든다.

    — 코드 컨벤션 주의사항

    💡
    1. 주소에는 _ 와 대문자를 쓰지 않는다 2. Class 에는 파스칼 표기법을 사용한다 3. 함수명은 카멜케이스를 사용한다 4. 주소에는 하이푼을 사용한다
     
     
    Share article

    하쎄의 기술 일기장

    RSS·Powered by Inblog