Thymeleaf Study Notes (Demo)

Source: Internet
Author: User

Project demo Http://pan.baidu.com/s/1wg6PC Learning materials URL http://www.blogjava.net/bjwulin/archive/2013/02/07/395234.html (not to do impetuous people                    ) Blog Http://www.tuicool.com/articles/yYZbIrB Basic Knowledge http://itutorial.thymeleaf.org/official Demo http://www.cnblogs.com/vinphy/p/4673918.html This article address SPRINGMVC + thymeleaf demo step: 1. Build a SPRINGMVC Project 2. Add Jar Pack 3 . Configure the Servlet4 in Web. config. Configure thymeleaf-related configuration in the Servlet.xml folder 5. Import control is defined in Cotroller 6. Add a static page to the project, adding a thymeleaf tag 7. Deployment Access-- System windows7--Development Tools IntelliJ idea--Project management tools maven--Automation build Tools gradle--Templates thymeleaf--Framework Springmvc 1. Build a SPRINGMVC project with a new IntelliJ    A SPRINGMVC project See Http://note.youdao.com/share/?id=89349b4e4f6f57ae603c2c43bad1bb62&type=note 2. Add Jar Package 1) gradle plus jar Package
Compile ("Org.springframework.boot:spring-boot-starter-thymeleaf")
2) Jar Package http://www.thymeleaf.org/download.html official website 3. Configuring the servlet in Web. xml
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns= "Http://java.sun.com/xml/ns/javaee"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "version= "3.0" > <!--configuration web-inf servlet-context.xml Files--<servlet> <servlet-name>appservle T</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param- Value>/web-inf/servlet-context.xml</param-value> </init-param> <load-on-startup>1</l oad-on-startup> </servlet> <servlet-mapping> &LT;SERVLET-NAME&GT;APPSERVLET&LT;/SERVLET-NAME&G        T <url-pattern>/</url-pattern> </servlet-mapping></web-app>
4. Configure Thymeleaf-related configuration in the configured Servlet.xml folder
<?xml version= "1.0" encoding= "UTF-8"? ><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-3.1.xsdhttp//Www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsd">
<!--Scans the classpath of ThisApplication for@Components to deploy as beans--<context:component-scan base- Package= "Com.test.thymeleaf.controller"/>
<!--configures the @Controller programming model--<mvc:annotation-driven/>
<!--resolves view names toprotected. JSP resources within The/web-inf/views directory--<!--springmvc+jsp's jump page configuration-<!--<beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver" >--> <!--<property name= "pref IX "value="/web-inf/views/"/>--> <!--<property name=" suffix "value=". JSP "/>--> < !--</bean>-->
<!--Springmvc+thymeleaf's jump page configuration--<bean id= "Templateresolver"class= "Org.thymeleaf.templateresolver.ServletContextTemplateResolver" > <property name= "prefix" value= "/web-inf/v iews/"/> <property name=" suffix "value=". html "/> <property name=" Templatemode "value=" HTML5 " /> </bean> <bean id= "Templateengine"class= "Org.thymeleaf.spring4.SpringTemplateEngine" > <property name= "templateresolver" ref= "Templateresolver"/&G T </bean> <beanclass= "Org.thymeleaf.spring4.view.ThymeleafViewResolver" > <property name= "templateengine" ref= "Templateengine"/& Gt </bean></beans>
5. Defining ingress Control in Cotroller
 PackageCom.test.thymeleaf.controller;ImportCom.test.thymeleaf.domain.User;ImportOrg.springframework.stereotype.Controller;ImportOrg.springframework.ui.Model;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestMethod; @Controller Public classHomeController {User User=NewUser ();
Entry @RequestMapping (Value= "/Home") PublicString Home (model) {Model.addattribute ("User", user); return"AA"; }
Data is read after the form is submitted and the data is passed out @RequestMapping (value= "/bb", method =requestmethod.post) PublicString BB (User user,model Model) {Model.addattribute ("User", user); Model.addattribute ("Message", ", welcome"); return"BB"; }}
6. Add a static page to the project and attach the Thymeleaf tag Note header file
<! DOCTYPE html>      xmlns:th= "http://www.thymeleaf.org" >
aa.html (define form data submission object with Th:object, define form data property with Th:field, lock object defined by the ancestor with *{}, fill in object properties within {}, and automatically drop attribute value when submitting form to object)
<! DOCTYPE html>      xmlns:th= "http://www.thymeleaf.org" >

bb.html (using ${} to read the data from the background dynamically replace the static data "vinphy," and "welcome!")

<! DOCTYPE html>      xmlns:th= "http://www.thymeleaf.org" >

7. Deployment Access

Access to Http://localhost:8080/home after deployment, aa.html content appears

Thymeleaf Study Notes (Demo)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.