Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags more
Archives
Today
Total
관리 메뉴

기록

JAVA Spring tiles 설정 본문

JAVA

JAVA Spring tiles 설정

9400 2023. 1. 26. 13:51
  • 반복적으로 사용되는 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"/>
Comments