1.采用idea 中的Spring initializr创建Spring boot 项目
2.添加pom依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--用来渲染页面 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3.新建一个Controller
@Controller
public class HelloController {
@RequestMapping(value = "/index",method = RequestMethod.GET)
public String hellohtml ()
{
return "/index";
}
}
4. 在resources中的templates文件夹下添加index.html文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" >
<title>Title</title>
</head>
<body>
这个是首页
</body>
</html>
5. 准备就绪,运行Application文件出现异常。
6. 查看控台发现日志信息如下
org.xml.sax.SAXParseException: 元素类型 “meta” 必须由匹配的结束标记 "</meta>"
终止。
7. 解决:将上面html文件做出如下修改
<meta charset="UTF-8" > 更改前
<meta charset="UTF-8" /> 更改后