一.前言

二.整合

1.poml. 添加包
		<dependency>
			<groupId>org.spring work.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>net.sourceforge.nekohtml</groupId>
			<artifactId>nekohtml</artifactId>
		</dependency>
2.application. 配置
spring:
  thymeleaf:
      mode: LEGACYHTML5
      cache: false
      suffix: .html
      encoding: UTF-8
      servlet:
        content-type: text/html
      prefix: classpath:/templates/
3.测试

在resources文件夹下面新建文件夹templates.新建regist.html文件 regist.html

<!DOCTYPE html>
<html lang=\"en\"  ns:th=\"http://www.w3.org/1999/xhtml\">
<head>
    <  charset=\"UTF-8\">
</head>
<body>
  <div>
      <div>  name: <span th:text=\"${name}\"/></div>

      <div>  username: <span th:text=\"${user.username}\"/></div>
      <div>  password: <span th:text=\"${user.password}\"/></div>

  </div>
</body>
</html>

2.controller层

@Controller
public class ViewsController {

    @GetMapping(\"/regist\")
    public ModelAndView regist(){
        ModelAndView view = new ModelAndView(\"regist\");
        User user = new User(\"lss0555\",\"123456\");
        view.add (\"name\",\"lss\");
        view.add (\"user\",user);
        return view;
    }
}

3.访问
访问 http://localhost:8085/regist 路径 ,结果:

name: lss
username: lss0555
password: 123456
收藏 打印