Spring in Action 4 6.3 using Apache Tiles

Source: Internet
Author: User

Configuring the Tiles View Resolver

Requires a tilesconfigurer bean, which is used to locate and load the tile definition, and also requires a tilesviewresolver Used to map the logical view name to the tile definition. In Webconfig.java

 @Configuration @enablewebmvc@componentscan (basepackageclasses={ Autoscan.class}) public class webconfig extends webmvcconfigureradapter {@ Overridepublic void configuredefaultservlethandling (Defaultservlethandlerconfigurer configurer)  {configurer.enable ();} 6th Chapter Content  6.3@beanpublic tilesconfigurer tilesconfigurer ()  {TilesConfigurer tiles  = new tilesconfigurer (); Tiles.setdefinitions (new string[] {  "/WEB-INF/layout/ Tiles.xml ", "/web-inf/views/**/tiles.xml " }); Tiles.setcheckrefresh (true); return tiles;} 6th Chapter Content  6.3@beanpublic viewresolver viewresolver ()  {return new tilesviewresolver ();}}

The Apache tiles now has two versions 2.0 and 3.0, with 3.0. What's the difference between the two? In fact, there is no difference, that is, the package name is different. Two versions require a tilesconfigurer Bean and tilesviewresolver Bean. When referencing, 2.0 used org.springframework.web.servlet .view.tiles2, and 3.0 with the org.springframework .web.servlet.view.tiles3.

The most important thing when configuring Tilesconfigurer beans is the definition of the attribute definitions. This property holds an array of strings, each of which specifies a tile-definition XML file. In the above configuration we are using the

Tiles.setdefinitions (new string[] {"/web-inf/layout/tiles.xml", "/web-inf/views/**/tiles.xml"});

This means that in addition to using/web-inf/layout/tiles.xml, all files named Tiles.xml in the/web-inf/views/folder and its subfolders are queried recursively and then used.

The tilesconfigurer/tilesviewresolveris configured with a Java configuration, and the equivalent XML configuration is shown below

<bean id= "Tilesconfigurer" class= "Org.springframework.web.servlet.view.tiles3.TilesConfigurer" >< Property name= "Definitions" ><list><value>/web-inf/layout/tiles.xml.xml</value><value >/web-inf/views/**/tiles.xml</value></list></property></bean><bean id= " Viewresolver "class=" Org.springframework.web.servlet.view.tiles3.TilesViewResolver "/>

The following is a description of the framework's core file tiles.xml.

Tiles.xml file Length This is the case. The mapping of the logical view name to the physical view file is defined, and it is found in the following content that all definitions are extends base, and base loads a header and a footer, so extends The definition of base has the same header and footer.

<?xml version= "1.0"  encoding= "Iso-8859-1"  ?><! 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= "Base"  template= "/web-inf/layout/page.jsp" >    <put-attribute  Name= "header"  value= "/web-inf/layout/header.jsp"  />    <put-attribute  name= "Footer"  value= "/web-inf/layout/footer.jsp"  />  </definition>   <definition name= "Home"  extends= "base" >    <put-attribute  Name= "Body"  value= "/web-inf/views/home.jsp"  />  </definition>  < Definition name= "Registerform"  extends= "base" >  &nbSp; <put-attribute name= "Body"  value= "/web-inf/views/registerform.jsp"  />   </definition>  <definition name= "Profile"  extends= "base" >     <put-attribute name= "Body"  value= "/web-inf/views/profile.jsp"  />   </definition>  <definition name= "Spittles"  extends= "base" >     <put-attribute name= "Body"  value= "/web-inf/views/spittles.jsp"  />  </ Definition>  <definition name= "spittle"  extends= "base" >     <put-attribute name= "Body"  value= "/web-inf/views/spittle.jsp"  />  </ Definition></tiles-definitions>

In the Tiles.xml file above, a definition is a tile, and each tile is a logical view and a physical view file map.

The book also has a description of page.jsp , how to define how the tile layout, how to load footer,body,header and so on. Involved in the front of the thing, looked at the head big.

Code structure

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/8A/6E/wKioL1gv9nvg0IeTAAH21aVgPRQ274.png "title=" Qq20161119145155.png "alt=" Wkiol1gv9nvg0ietaah21avgprq274.png "/>

First time to start the times wrong

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/8A/6D/wKioL1gv833hUaKNAAJbgSU-R0Q199.png "title=" Qq20161119143913.png "alt=" Wkiol1gv833huaknaajbgsu-r0q199.png "/>

Since there is no package to introduce tiles, after adding the following in Build.gradle, refresh Gradle can

Compile ("Org.apache.tiles:tiles-core: $tilesVersion") {Exclude group: ' Org.slf4j '}compile ("Org.apache.tiles: tiles-jsp: $tilesVersion ") {Exclude group: ' ORG.SLF4J '}

Restart the server again

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/8A/6E/wKioL1gv9xiRdr_mAAEfYedPI7o063.png "title=" Qq20161119144941.png "alt=" Wkiol1gv9xirdr_maaefyedpi7o063.png "/>

This version of Spring in action is the spring in Action4 author is also very kind, the relevant pictures are provided. The 3rd version of the source code is not found in a long time did not find. Of course, my search ability is almost.

Many of the pictures in this article are from the source code, the copyright belongs to the original author. The path is consistent with the source code. No difference.

I guess the author looks like this ... I don't know if it's true. I hope not. LOL

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/6F/wKioL1gv-jDQMF35AAAIegLZ8kU593.jpg "title=" Spitter_me.jpg "alt=" Wkiol1gv-jdqmf35aaaieglz8ku593.jpg "/>

This article from "Dream do not know is a guest" blog, reproduced please contact the author!

Spring in Action 4 6.3 using Apache Tiles

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.