기록
JAVA Spring tiles 설정 본문
- 반복적으로 사용되는 header, footer와 같은 정보를 한곳에 모아둔 프레임워크.
- 화면 기본 구성 레이아웃 템플릿 정의하고 상속을 통하여 대부분 구조를 재사용할 수 있는 기능 및 설정파일을 통한 통합 관리를 통하여 확장성 있고 일관되게 페이지 구성을 관리한다.
pom.xml
<!-- tiles 시작 -->
<!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-extras -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.8</version>
</dependency>
<!-- 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>
<!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-jsp -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.8</version>
</dependency>
<!-- tiles 끝 -->
servlet-context.xml (우선순위 표시)
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- 스트링 웹(view) 설정 파일 -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<!-- static folder설정(정적폴더설정) => css,images, upload, js
http://localhost/resources/
-->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<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:bean>
<!-- Tiles 설정 시작 -->
<beans:bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/spring/tiles-config.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<!-- UrlBasedViewResolver tilesViewResolver = new UrlBasedViewResolver(); -->
<beans:bean id="tilesViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass"
value="org.springframework.web.servlet.view.tiles3.TilesView" />
<beans:property name="order" value="1" />
</beans:bean>
<!-- Tiles 설정 끝 -->
<context:component-scan base-package="kr.or.ddit" />
</beans:beans>
tiles-config.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 설정 -->
<tiles-definitions>
<!-- main layout -->
<definition name="tiles-layout" template="/WEB-INF/views/tiles/index.jsp">
<put-attribute name="header" value="/WEB-INF/views/tiles/header.jsp" />
<put-attribute name="aside" value="/WEB-INF/views/tiles/aside.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/views/tiles/footer.jsp" />
</definition>
<!-- name의 */*은 body의 value에서 1과 2에 해당
controller에서 forwarding 시 return "1/2";
-->
<definition name="*/*" extends="tiles-layout">
<put-attribute name="body" value="/WEB-INF/views/{1}/{2}.jsp" />
</definition>
</tiles-definitions>
아래와 같이 사용
<tiles:insertAttribute name="header" />
<div class="container-fluid">
<tiles:insertAttribute name="body" />
</div>
<tiles:insertAttribute name="footer"/>
'JAVA' 카테고리의 다른 글
JAVA Spring 파일 업로드 예제 +미리보기 (0) | 2023.01.30 |
---|---|
JAVA Spring 파일업로드 설정 및 업로드하기 (0) | 2023.01.27 |
JAVA 스프링 root-context.xml 설정 (0) | 2023.01.19 |
JAVA 스프링 pom.xml 설정 (mybatis, lombok) (0) | 2023.01.19 |
JAVA 스프링 한글처리web.xml 설정 (0) | 2023.01.19 |
Comments