본문 바로가기

개발(합니다)/Java&Spring

[Spring] tiles3 설정

반응형

도로명 주소 API를 만들면서 설정 한 postgresql과 mybatis를 설정 한 과정을 남깁니다.

1. POM 설정

tiles 추가
<!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-servlet -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-servlet</artifactId>
            <version>3.0.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>3.0.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-core</artifactId>
            <version>3.0.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-api</artifactId>
            <version>3.0.8</version>
        </dependency>
레이아웃 라이브러리
sitemesh도 있지만 tiles를 쓰고 있습니다.
상대적으로 sitemesh가 사용이 쉽고 기능도 적습니다.
tiles가 기능이 많지만 전부 사용하지 않습니다.


2. tiles3 설정


tiles, layouts, tiles.xml을 만듭니다.



    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
        <beans:property name="order" value="2"/>
        <beans:property name="contentType" value="text/html; charset=UTF-8"/>
    </beans:bean>

    
<bean id="tilesViewResolver"
        class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
        <property name="order" value="1" />
    </bean>
    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles/tiles.xml</value>
            </list>
        </property>
    </bean>
tiles Resolver와 configurer를 추가합니다.

<?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>
    <definition name="base" template="/WEB-INF/tiles/layouts/defaultLayout.jsp">
        <put-attribute name="title" value="addr" />
        <put-attribute name="footer"
            value="/WEB-INF/tiles/layouts/defaultFooter.jsp" />
        <put-attribute name="header"
            value="/WEB-INF/tiles/layouts/defaultHeader.jsp" />
        <put-attribute name="header-menu"
            value="/WEB-INF/tiles/layouts/defaultHeadermenu.jsp" />
        <put-attribute name="side-menu"
            value="/WEB-INF/tiles/layouts/defaultSidemenu.jsp" />
    </definition>

    <definition name="/index" extends="base">
        <put-attribute name="contents" value="/index.jsp" />
    </definition>
    
    <definition name="empty" template="/WEB-INF/tiles/layouts/emptyLayout.jsp">
        <put-attribute name="contents" value="/WEB-INF/tiles/layouts/empty.jsp" />
    </definition>
    <definition name="*" extends="base">
        <put-attribute name="contents" expression="/WEB-INF/views/{1}.jsp" />
    </definition>

    <definition name="*/*" extends="base">
        <put-attribute name="contents" expression="/WEB-INF/views/{1}/{2}.jsp" />
    </definition>

    <definition name="*/*/*" extends="base">
        <put-attribute name="contents" expression="/WEB-INF/views/{1}/{2}/{3}.jsp" />
    </definition>

</tiles-definitions>
tiles.xml 작성합니다.
타일즈는 추가 하지 않아도 무방합니다.


3. 실행 화면


반응형