02 thymeleaf unusual problems arise

SpringBoot + Thyemleaf normal development environment, packaged jar to the server on the error Template might not exist or might not be accessible

1. In the controller layer over request processing returns, without non-return json format @RestController or @ResponseBody

2. html return path and name of your controller in the process corresponding to the layer in front added an extra /.

For example return "/ index", the official / error cause, the solution: remove the front of the return / can, for example, return "index".

3. Use springboot course, if thymeleaf as a template file, requires HTML format must be strictly html5 format, it must have an end tag, otherwise it will error.

#thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
再在pom.xml 添加以下依赖

  1. <dependency>
  2. <groupId>net.sourceforge.nekohtml</groupId>
  3. <artifactId>nekohtml</artifactId> 
  4. <version>1.9.22</version>
  5. </dependency>

Guess you like

Origin www.cnblogs.com/lazyli/p/10949717.html