
๐์๋ชป๋ ์ค๋ช ์ ๋ํ ์ง์ ์ด๋ ์กฐ์ธ์ ๋๊ธ์ ํ์ํฉ๋๋ค๐
tiles๋
View page๋ก ์ ๊ณตํ๋ jsp ํ์ผ์ ์ค๋ณต๋๋ ์์๋ฅผ ํ์ด์ง ์กฐ๊ฐ์ผ๋ก ๋๋์ด ๊ด๋ฆฌํ๋๋ก ๋๋ ํ ํ๋ฆฟ ๊ตฌ์ฑ ํ๋ ์์ํฌ
https://tiles.apache.org/framework/index.html
Apache Tiles - Framework - Home
tiles.apache.org
tiles์ ๊ฐ๋จ ์ฌ์ฉ๋ฒ
ํ๋ก์ ํธ์์ tiles๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ pom.xml ํ์ผ์์ maven dependency๋ฅผ ๊ฐ์ฅ ๋จผ์ ์ถ๊ฐํ๋ค.
<!-- tiles framework -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.8</version>
</dependency>
<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>
๊ทธ ๋ค์ Servlet-Context.xml ํ์ผ์์ tiles bean ์์ฑ์ด ๊ฐ๋ฅํ๋๋ก viewResolver์ Configurer๋ฅผ ์ค์ ํ๋ค.
- viewResolver: tiles template์ผ๋ก ์ค์ ๋ ํ์ผ์ ์ฐพ์์ ๋ ๋๋ง ํด์ฃผ๋ ์ญํ
<!-- Tiles ๋ทฐ ๋ฆฌ์กธ๋ฒ -->
<beans:bean id="tielsViewResolver"
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 ์ค์ ํ์ผ -->
<beans:bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/tiles/tiles.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
์ธ๋ฒ์งธ๋ก๋ tiles.xml๊ฐ ํ์ํ๋ค. ์์์ ์ ์ธํ๋๋ก /WEB-INF/tiles/tiles.xml ์์น์ 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="classic" template="/WEB-INF/tiles/layouts/classic.jsp">
<put-attribute name="TopMenu" value="/WEB-INF/tiles/components/TopMenu.jsp" />
<put-attribute name="SideBar" value="/WEB-INF/tiles/components/NewSideBar.jsp" />
</definition>
<definition name="*/*" extends="classic">
<put-attribute name="content" value="/WEB-INF/views/{1}/{2}.jsp" />
</definition>
</tiles-definitions>
์ ์์ ์ classic.jsp์ฒ๋ผ layout์ฉ jsp ํ์ผ์ ์์ฑํ๋ค.
tiles.xml ์์ put-attributeํ name์ผ๋ก template์ฉ jsp ํ์ผ ์์ tiles:insertAttributeํ๋ฉด ํ ํ๋ฆฟ์ ์ฝ๋์ insert๋ ์ฝ๋๊ฐ ํจ๊ป ๋ ๋๋ง ๋์ด ํ๋ฉด์ ํ์๋๋ค.
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<link href="css/common.css" rel="stylesheet">
<title>project titles</title>
</head>
<body>
<tiles:insertAttribute name="SideBar" />
<tiles:insertAttribute name="TopMenu" />
<tiles:insertAttribute name="content" />
</body>
</html>
Reference
'FE' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[HTML] Spring boot ํ๋ก์ ํธ์์ favicon ์ค์ (0) | 2023.01.28 |
---|---|
[JS] ํ์ ์ ์ ์ค์ํ๊ฐ (feat. TypeScript์ ํ์์ฑ) (0) | 2022.06.22 |
[HTML] ๋ค์ํ ์ ๊ทผ์ฑ ์์ฑ (0) | 2022.03.18 |
[JS์คํฐ๋] 27์ฅ ๋ฐฐ์ด (0) | 2022.03.12 |
[JS ์คํฐ๋] 9์ฅ ํ์ ๋ณํ๊ณผ ๋จ์ถ ํ๊ฐ, 10์ฅ ๊ฐ์ฒด ๋ฆฌํฐ๋ด (0) | 2022.03.05 |