ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Spring] FreeMarker 적용 ( + tiles)
    카테고리 없음 2020. 9. 17. 09:44

    WEB-INF > web.xml

    </web-app>바로위에 추가

    <!-- freemarker -->
    	<servlet>
    		<servlet-name>freemarker</servlet-name>
    		<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
    	
    		<!-- FreemarkerServlet settings: -->
    		<init-param>
    			<param-name>TemplatePath</param-name>
    			<param-value>/</param-value>
    		</init-param>
    		<init-param>
    			<param-name>NoCache</param-name>
    			<param-value>true</param-value>
    		</init-param>
    		<init-param>
    			<param-name>ContentType</param-name>
    			<param-value>text/html; charset=UTF-8</param-value> <!-- Forces UTF-8 output encoding! -->
    		</init-param>
    	
    		<!-- FreeMarker settings: -->
    		<init-param>
    			<param-name>template_update_delay</param-name>
    			<param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. -->
    		</init-param>
    		<init-param>
    			<param-name>default_encoding</param-name>
    			<param-value>UTF-8</param-value> <!-- The encoding of the template files. -->
    		</init-param>
    		<init-param>
    			<param-name>number_format</param-name>
    			<param-value>0.##########</param-value>
    		</init-param>
    	
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>freemarker</servlet-name>
    		<url-pattern>*.ftl</url-pattern>
    	</servlet-mapping>  

     

    pom.xml

    Dependency 추가

    		<!-- FreeMarker -->
    		<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker-gae -->
    		<dependency>
    			<groupId>org.freemarker</groupId>
    			<artifactId>freemarker</artifactId>
    			<version>2.3.30</version>
    		</dependency>

    *타일즈 사용시

    		<dependency>
    			<groupId>org.apache.tiles</groupId>
    			<artifactId>tiles-jsp</artifactId>
    			<version>${org.tiles-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.tiles</groupId>
    			<artifactId>tiles-servlet</artifactId>
    			<version>${org.tiles-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.tiles</groupId>
    			<artifactId>tiles-core</artifactId>
    			<version>${org.tiles-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.tiles</groupId>
    			<artifactId>tiles-template</artifactId>
    			<version>${org.tiles-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.tiles</groupId>
    			<artifactId>tiles-freemarker</artifactId>
    			<version>${org.tiles-version}</version>
    		</dependency>

     

    tiles.xml 수정

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE tiles-definitions PUBLIC
    	"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
    	"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
     
    <tiles-definitions>
    	
    	<!-- 화면의 기초가 되는 base -->
    	<definition name="base" template="/WEB-INF/views/tiles/layout/template.ftl" >
    		<put-attribute name="nav"   value="/WEB-INF/views/tiles/comm/nav.ftl"  />
    		<put-attribute name="header" value="/WEB-INF/views/tiles/comm/header.ftl"  />
    		<put-attribute name="footer" value="/WEB-INF/views/tiles/comm/footer.ftl"  />
    	</definition>
    	
    	
    	<!-- 동적 매핑. 만약 /user/login의 경로라면 /WEB-INF/views/user/login.jsp 뷰를 가져온다. -->
    	<definition name="*" extends="base">
    		<put-attribute name="body" value="/WEB-INF/views/{1}.ftl" />
    	</definition>
     
    	 <definition name="*/*" extends="base">
    		 <put-attribute name="body" value="/WEB-INF/views/{1}/{2}.ftl" />
    	 </definition>
    	
    	<definition name="*/*/*" extends="base">
    		<put-attribute name="body" value="/WEB-INF/views/{1}/{2}/{3}.ftl" />
    	</definition>
    </tiles-definitions>
    

     

    project tree

     

    jsp > freemarker로 변경

    댓글

Designed by Tistory.