Springboot跳转html页面

1.首先在pom文件中引入模板引擎jar包

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2.在application.properties中配置模板引擎

sping.thymeleaf.prefix=classpath:/templates/

3.在templates下建立hello.html文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
</head>
<body>
<h1>hello world!</h1>
</body>
</html>
4.写controller
package com.example;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by hzm on 2017/4/1.
 */
@Controller
public class HelloController {


    @RequestMapping("/test")
    public String test(){ 
        return "hello";
    }
}

5.输入网址

http://localhost:8080/test

6.页面会出现

hello world!

猜你喜欢

转载自blog.csdn.net/ctgu361663454/article/details/80226150