Tip/Spring

Spring MVC + Thymeleaf

JavaPark 2013. 7. 24. 16:13


* 테스트 환경 

- Windows 7 64bit

- STS 3.2.0 ( VMware vFabric tc Server Developer Edition v2.7 )

- thymeleaf 2.0.17



  Spring MVC + Thymeleaf 적용



STS를 이용하여 Spring MVC + Thymeleaf 적용하기


1. Spring MVC 프로젝트 생성

2. pom.xml

### xml

<dependency>

<groupId>org.thymeleaf</groupId>

<artifactId>thymeleaf</artifactId>

<version>2.0.17</version>

</dependency>

<dependency>

<groupId>org.thymeleaf</groupId>

<artifactId>thymeleaf-spring3</artifactId>

<version>2.0.17</version>

</dependency>

<dependency>

<groupId>org.thymeleaf</groupId>

<artifactId>thymeleaf-testing</artifactId>

<version>2.0.3</version>

</dependency>


3. servlet-context.xml

### xml

<!-- **************************************************************** -->

<!-- THYMELEAF-SPECIFIC ARTIFACTS -->

<!-- TemplateResolver <- TemplateEngine <- ViewResolver -->

<!-- **************************************************************** -->

<beans:bean id="templateResolver"

class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">

<beans:property name="prefix" value="/WEB-INF/templates/" />

<beans:property name="suffix" value=".html" />

<beans:property name="templateMode" value="HTML5" />

</beans:bean>

<beans:bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">

<beans:property name="templateResolver" ref="templateResolver" />

</beans:bean>

<beans:bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">

<beans:property name="templateEngine" ref="templateEngine" />

</beans:bean>


4. home.html

### html

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring3-3.dtd">


<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:th="http://www.thymeleaf.org">

<head>

<title>Thymeleaf Home</title>

</head>

<body>

<h1>Thymeleaf Hello world!</h1>


<P>The time on the server is</P>

</body>

</html>




  참고


http://www.thymeleaf.org

http://www.thymeleaf.org/springsecurity.html