spring-boot-starter-thymeleaf avoid pit Guide

spring-boot-starter-thymeleaf avoid pit Guide

The first step: pom configuration environment to forget about the package is doing what must be a word or into the pit

 1 <!--避坑包-->
 2       <dependency>
 3           <groupId>net.sourceforge.nekohtml</groupId>
 4           <artifactId>nekohtml</artifactId>
 5           <version>1.9.22</version>
 6       </dependency>
 7        <!--解析html包-->
 8       <dependency>
 9           <groupId>org.springframework.boot</groupId>
10           <artifactId>spring-boot-starter-thymeleaf</artifactId>
11 </dependency>

 

Step Two: Configure application.properties 

       Note 1. The end must be ------ #thymeleaf end --------- otherwise off pit

                2. # template coding spring.thymeleaf.mode = LEGACYHTML5

                To use this LEGACYHTML5 encoding format to be introduced in the above pom 'to avoid the pit package' otherwise not take

               Sure some people ask why not HTML5, you can try

                Because you might find in the default configuration, thymeleaf for the content .html very strict requirements, such as <meta charset = "UTF-8" />,

                If the last few labels closed symbols /, and the error will go to the wrong page. For example, you can use this library Vue.js, then there <div v-cloak> </ div> such html code,

               Thymeleaf will be considered non-compliant and throw an error. Therefore, the proposed increase in the following passage:

                 = LEGACYHTML5 spring.thymeleaf.mode
                 spring.thymeleaf.mode default is HTML5, in fact, is a very stringent checks, instead LEGACYHTML5 might get a more friendly and intimate format requirements.

               Note that, LEGACYHTML5 need to match an additional library NekoHTML available also to avoid the pit when the package above

 

1 # <! - use the cache when you close thymeleaf develop otherwise there is no real-time images ->
 2 spring.thymeleaf.cache = false 
3  ## checks whether there is a template, and then presented
 4 spring.thymeleaf.check-Template-LOCATION = to true 
. 5 # Content- the type value
 . 6 spring.thymeleaf.content-type = text / HTML
 . 7  # view MVC Thymeleaf enable resolution
 . 8 spring.thymeleaf.enabled = to true 
. 9  comma ## should be excluded from the solution separated list view name
 10 ## spring.thymeleaf.excluded-View-names =
 . 11  # encoding template
 12 is spring.thymeleaf.mode = LEGACYHTML5
 13 is  # prefix name view in advance at the time of constructing the URL
 14CLASSPATH = spring.thymeleaf.prefix: / Templates /
 15  . See # build additional URL name suffix
 16 spring.thymeleaf.suffix = .html
 . 17  sequence # parser template strand
 18 is # spring.thymeleaf.template-resolver- = Order O
 . 19  # can resolve the name of a comma separated list of the view
 20 is # = names spring.thymeleaf.view-
 21 is #thymeleaf End

 

This is my static page structure

 

   The third step: controller layer

   It must be injected when the Controller is not RestController rest because it is the interface (json format) is less than parsing html

 

 1 @Controller  注意不要是RestController
 2 @RequestMapping(value = "/")
 3 public class MainController {
 4  
 5  
 6     @Autowired
 7     MainService mainService;
 8  
 9           @GetMapping(value = "/home")
10           public String homePage(){
11  
12               return "test";
13           }
14 }

 

 Where it is not so much demand on the use of the original ecological casual play where want to jump jump

1 @GetMapping(value = "/home")
2           public void homePage(HttpServletResponse response)throws IOException{
3               response.sendRedirect("index.html");
4 //              return "index";
5           }

 

Pass value if required, java interface using a normal method can be 

model.addAttribute("yu","Hello world Thymeleaf");

 

Need to address referenced in the html tag in html interface. thymeleaf using OGNL label, and the label jstl almost personal feeling, such as:

<html lang="en" xmlns:th="http://www.thymeleaf.org">

<!--/*@thymesVar id="yu" type="java"*/-->
<p th:text="${yu}"></p>

I use the IDEA compiled using the tag, then an error will only add <-! / * @ ThymesVar id = "yu" type = "java" * / -> Notes was not being given

Label, then do not need to write your own, click on the left being given the red dot label comments will be prompted to automatically generate

 

Reprinted from: https://www.cnblogs.com/memoryXudy/p/7681991.html

 

spring-boot-starter-thymeleaf avoid pit Guide

The first step: pom configuration environment to forget about the package is doing what must be a word or into the pit

 1 <!--避坑包-->
 2       <dependency>
 3           <groupId>net.sourceforge.nekohtml</groupId>
 4           <artifactId>nekohtml</artifactId>
 5           <version>1.9.22</version>
 6       </dependency>
 7        <!--解析html包-->
 8       <dependency>
 9           <groupId>org.springframework.boot</groupId>
10           <artifactId>spring-boot-starter-thymeleaf</artifactId>
11 </dependency>

 

Step Two: Configure application.properties 

       Note 1. The end must be ------ #thymeleaf end --------- otherwise off pit

                2. # template coding spring.thymeleaf.mode = LEGACYHTML5

                To use this LEGACYHTML5 encoding format to be introduced in the above pom 'to avoid the pit package' otherwise not take

               Sure some people ask why not HTML5, you can try

                Because you might find in the default configuration, thymeleaf for the content .html very strict requirements, such as <meta charset = "UTF-8" />,

                If the last few labels closed symbols /, and the error will go to the wrong page. For example, you can use this library Vue.js, then there <div v-cloak> </ div> such html code,

               Thymeleaf will be considered non-compliant and throw an error. Therefore, the proposed increase in the following passage:

                 = LEGACYHTML5 spring.thymeleaf.mode
                 spring.thymeleaf.mode default is HTML5, in fact, is a very stringent checks, instead LEGACYHTML5 might get a more friendly and intimate format requirements.

               Note that, LEGACYHTML5 need to match an additional library NekoHTML available also to avoid the pit when the package above

 

1 # <! - use the cache when you close thymeleaf develop otherwise there is no real-time images ->
 2 spring.thymeleaf.cache = false 
3  ## checks whether there is a template, and then presented
 4 spring.thymeleaf.check-Template-LOCATION = to true 
. 5 # Content- the type value
 . 6 spring.thymeleaf.content-type = text / HTML
 . 7  # view MVC Thymeleaf enable resolution
 . 8 spring.thymeleaf.enabled = to true 
. 9  comma ## should be excluded from the solution separated list view name
 10 ## spring.thymeleaf.excluded-View-names =
 . 11  # encoding template
 12 is spring.thymeleaf.mode = LEGACYHTML5
 13 is  # prefix name view in advance at the time of constructing the URL
 14CLASSPATH = spring.thymeleaf.prefix: / Templates /
 15  . See # build additional URL name suffix
 16 spring.thymeleaf.suffix = .html
 . 17  sequence # parser template strand
 18 is # spring.thymeleaf.template-resolver- = Order O
 . 19  # can resolve the name of a comma separated list of the view
 20 is # = names spring.thymeleaf.view-
 21 is #thymeleaf End

 

This is my static page structure

 

   The third step: controller layer

   It must be injected when the Controller is not RestController rest because it is the interface (json format) is less than parsing html

 

 1 @Controller  注意不要是RestController
 2 @RequestMapping(value = "/")
 3 public class MainController {
 4  
 5  
 6     @Autowired
 7     MainService mainService;
 8  
 9           @GetMapping(value = "/home")
10           public String homePage(){
11  
12               return "test";
13           }
14 }

 

 Where it is not so much demand on the use of the original ecological casual play where want to jump jump

1 @GetMapping(value = "/home")
2           public void homePage(HttpServletResponse response)throws IOException{
3               response.sendRedirect("index.html");
4 //              return "index";
5           }

 

Pass value if required, java interface using a normal method can be 

model.addAttribute("yu","Hello world Thymeleaf");

 

Need to address referenced in the html tag in html interface. thymeleaf using OGNL label, and the label jstl almost personal feeling, such as:

<html lang="en" xmlns:th="http://www.thymeleaf.org">

<!--/*@thymesVar id="yu" type="java"*/-->
<p th:text="${yu}"></p>

I use the IDEA compiled using the tag, then an error will only add <-! / * @ ThymesVar id = "yu" type = "java" * / -> Notes was not being given

Label, then do not need to write your own, click on the left being given the red dot label comments will be prompted to automatically generate

 

Reprinted from: https://www.cnblogs.com/memoryXudy/p/7681991.html

 

Guess you like

Origin www.cnblogs.com/swanyf/p/10942543.html