• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Spring 게시판 Thymeleaf 대신 pug 쓰기

Thymeleaf 대신 pug 쓰기

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #130481

    김지한
    참가자
    Spring에서 권장하는 Thymeleaf를 쓰는게 취업에는 좋을지 몰라도 , 저는 재미가 우선이라서 ㅋㅋㅋ
    pug 로 세팅하는 방법을 알아내서 잘 사용중입니다.
    타임리프보다 편리한 점이 많은데
    예를 들어
    nav파일 포함하는거 include nav.pug 하면 끝, 간결한 문법이 좋아서 쓰고있어요.
    ----------
    body
        include nav.pug
        h4 메인페이지
    ---------
    Pug가 괄호가 적고 파이썬 스타일의 들여쓰기로 위계를 파악하는거라, 파이썬을 좋아하면
    금방 익숙해질것같아요.
    혹시 관심있으신 분은 한번 해보세요.
     
    세팅법
    ----------------------
    build.gradle
    dependencies {
        // Pug
        implementation 'de.neuland-bfi:spring-pug4j:3.2.0'
    }
    ---------------------
    위의것 추가하시고
    com.apple.shop 아래에 Config 폴더 만들어서
    PugConfig라는 클래스를 만들고
    -----------------------
    package com.apple.shop.Config;
    import de.neuland.pug4j.PugConfiguration;
    import de.neuland.pug4j.spring.template.SpringTemplateLoader;
    import de.neuland.pug4j.spring.view.PugViewResolver;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    @Configuration
    public class PugConfig {
      @Bean
      public SpringTemplateLoader templateLoader() {
        SpringTemplateLoader templateLoader = new SpringTemplateLoader();
        templateLoader.setTemplateLoaderPath("classpath:/templates");
        templateLoader.setEncoding("UTF-8");
        templateLoader.setSuffix(".pug");
        return templateLoader;
      }
      @Bean
      public PugConfiguration pugConfiguration() {
        PugConfiguration configuration = new PugConfiguration();
        configuration.setCaching(false);
        configuration.setTemplateLoader(templateLoader());
        return configuration;
      }
      @Bean
      public PugViewResolver viewResolver() {
        PugViewResolver viewResolver = new PugViewResolver();
        viewResolver.setConfiguration(pugConfiguration());
        return viewResolver;
      }
    }
    ----------------------------
    이렇게 파일하나 만들면 되더군요.
    컨트롤러 클래스에서는
    -----------------------
    @GetMapping("/")
    String index() { 
    return "index";
    }
    -------------------
    index다음에 확장자 안붙이면 pug파일을 렌더링 해줍니당.
    • 이 게시글은 김지한에 의해 9 월, 2 주 전에 수정됐습니다.
    • 이 게시글은 김지한에 의해 9 월, 2 주 전에 수정됐습니다.
    • 이 게시글은 김지한에 의해 9 월, 2 주 전에 수정됐습니다.
    • 이 게시글은 김지한에 의해 9 월, 2 주 전에 수정됐습니다.
    • 이 게시글은 김지한에 의해 9 월, 2 주 전에 수정됐습니다.
    #130492

    codingapple
    키 마스터
    개추
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠