When you write a page, you often need to use generic modules, such as the header section, the footer section, and so on.
The front end of the project is using the Themeleaf template engine, and the following is a brief introduction to using Themeleaf to write the header generic module:
1. Common part: header2.html
Primarily using the Th:gragment property tag
<!DOCTYPE HTML><HTMLLang= "ZH-CN"xmlns:th= "http://www.thymeleaf.org"><Headth:fragment= "Common_header (title)"> <MetaCharSet= "UTF-8"> <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge"/> <titleTh:replace= "${title}">Head Real</title></Head><Body><Divclass= "header"style= "Height:auto;"th:fragment= "header">This is the content from the header module ...</Div></Body></HTML>
2. Reference section:
Primarily tagged with the Th:relpace property
Headdemo01.html
<!DOCTYPE HTML><HTMLLang= "ZH-CN"xmlns:th= "http://www.thymeleaf.org"><Head> <MetaCharSet= "UTF-8"> <title>HeadDemo01</title></Head><Body><DivTh:replace= "~{header2:: Header}"></Div>headDemo01</Body></HTML>
Headdemo02.html
<!DOCTYPE HTML><HTMLLang= "ZH-CN"xmlns:th= "http://www.thymeleaf.org"><Head> <MetaCharSet= "UTF-8"> <title>HeadDemo02</title></Head><Body><DivTh:replace= "~{header2:: Header}"></Div>headDemo02</Body></HTML>
Writing common modules in HTML using Thymeleaf