Spring tiles

Programming/Java 2016.07.09 19:22 Posted by 파란크리스마스

출처 : Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse

WEB-INF\web.xml

	<context-param>
		<param-name>spring.profiles.active</param-name>
		<param-value>tiles3</param-value>
	</context-param>

WEB-INF\intel4-tiles.xml

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
	

	<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".html" />
		<property name="templateMode" value="HTML5" />
		<property name="cacheable" value="true" />
	</bean>
	
	<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
		<property name="templateResolver" ref="templateResolver" />
	</bean>
	<bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
		<property name="templateEngine" ref="templateEngine" />
		<property name="order" value="1" />
		<property name="viewNames" value="thymeleaf/*" />
	</bean>

	<!-- Resolves view names to Tiles definitions -->
	<beans profile="tiles3">
		<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
			<property name="order" value="0"/>
		</bean>
	
		<!-- Configures Tiles 3-->
		<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
			<property name="definitions">
				<list>
					<value>/WEB-INF/jsp/tiles/tiles.xml</value>
					<!-- 
					<value>/WEB-INF/jsp/service/tiles.xml</value>
					<value>/WEB-INF/jsp/spiderview/tiles.xml</value>
					<value>/WEB-INF/jsp/spiderlive/tiles.xml</value>
					<value>/WEB-INF/jsp/customer/tiles.xml</value>
					<value>/WEB-INF/jsp/news/tiles.xml</value>
					<value>/WEB-INF/jsp/recruit/tiles.xml</value>
					<value>/WEB-INF/jsp/company/tiles.xml</value>
					<value>/WEB-INF/jsp/admin/tiles.xml</value>
					 -->
				</list>
			</property>
		</bean>
	</beans>

</beans>

WEB-INF\jsp\tiles\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>
	
	<definition name="/*.blank" template="/WEB-INF/jsp/common/layout/blankLayout.jsp">
		<put-attribute name="content"	value="/WEB-INF/jsp/admin/{1}.jsp"/>
	</definition> 
	
	<definition name="/*" template="/WEB-INF/jsp/tiles/web_layout.jsp">
		<put-attribute name="header" value="/WEB-INF/jsp/tiles/web_header.jsp" />
		<put-attribute name="main" value="/WEB-INF/jsp/{1}.jsp" />
		<put-attribute name="footer" value="/WEB-INF/jsp/tiles/web_footer.jsp" />	
	</definition>
	
</tiles-definitions>

WEB-INF\jsp\tiles\web_layout.jsp

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<!DOCTYPE HTML>
<html lang="ko">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0 minimal-ui"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black">
</head>

<body>

	<!-- head -->
	<tiles:insertAttribute name="header" />
	
	<!-- content -->
	<tiles:insertAttribute name="main" />

	<!-- footer -->
	<tiles:insertAttribute name="footer" />
	
</body>
</html>
저작자 표시
신고


 

티스토리 툴바