Springboot jump to html page

1. First introduce the template engine jar package in the pom file

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

2. Configure the template engine in application.properties

sping.thymeleaf.prefix=classpath:/templates/

3. Create a hello.html file under templates

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
</head>
<body>
<h1>hello world!</h1>
</body>
</html>
4. Write the 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. Enter the URL

http://localhost:8080/test

6. The page will appear

hello world!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325851233&siteId=291194637