2.启动类com.google.zxing core3.3.0 com.google.zxing javase3.3.0 junit junit4.13.1 test cn.hutool hutool-all5.4.0 com.alibaba fastjson1.2.74 org.springframework.boot spring-boot-starter-web2.0.5.RELEASE org.springframework.boot spring-boot-starter-thymeleaf2.0.1.RELEASE UTF-8 UTF-8 1.8 org.apache.maven.plugins maven-compiler-plugin1.8 1.8 UTF-8 org.springframework.boot spring-boot-maven-plugincom.SpringBootstrap repackage org.apache.maven.plugins maven-surefire-plugintrue src/main/java ***.yaml ***.properties ***.html false src/main/resources ***.yaml ***.properties ***.html false zxing-demo1
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ApplicationRun {
public static void main(String[] args) {
SpringApplication.run(ApplicationRun.class, args);
}
}
3.配置文件
server:
port: 9999
spring:
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: HTML5
encoding: UTF-8
cache: false
resources:
chain:
strategy:
content:
enabled: true
paths:
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping("/toindex")
public String toIndex(Model model) {
Map info = new HashMap<>();
info.put("title", "zhangsan");
info.put("profile", "18");
info.put("url", "http://www.baidu.com");
info.put("location", "aaaa");
model.addAttribute("info_list", Arrays.asList(info));
return "index";
}
}
html代码:
Title
hello thymeleaf
6.异常记录
An error happened during template parsing (template: "class path resource [*.html]")
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sun Jun 05 22:47:06 CST 2022 There was an unexpected error (type=Internal Server Error, status=500). An error happened during template parsing (template: "class path resource [templates/index.html]")
问题导致:thymeleaf的语法使用错误,这里犯错是因为thymeleaf循环语法使用错误
当然造成这个错误的原因可能还有很多,最重要的是检查thymeleaf的语法,如果代码比较多,可以使用“替换法”,原来代码备份后,大面积删除,到不报错就能够找到那里的语法错误,从而解决问题。这里补充一下thymeleaf的常用:
头注释:
1.循环用法:
2.if用法:
3.switch用法:
4.其他



