SpringBoot jump to a static html page && static file placement

SpringBoot jump to a static html page && static file placement

A, SpringBoot jump to a static html page

1, add spring-boot-starter-thymeleaf in pom.xml.

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

2. Establish a.html file in the templates, New qiu folder and create a folder b.html in qiu

SpringBoot jump to a static html page && static file placement

a.html reads as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>AAaaAA</h1>
</body>
</html>

b.html document reads as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>BBbbBB</h1>
</body>
</html>

3, a controller in the controller write the page to return at this time can not be used [@RestController, otherwise it will return the string]

package com.sic.equipment.controller;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@EnableAutoConfiguration
@RequestMapping("/a")
public class TestController {
    @RequestMapping("/2")
    public String aa(){
        return "a";
    }

    @RequestMapping("/3")
    public String ab(){
        return "qiu/b";
    }
}

4, respectively, to access the browser visit: http://127.0.0.1:502/1/2 and http://127.0.0.1:502/1/3

SpringBoot jump to a static html page && static file placement

SpringBoot jump to a static html page && static file placement

Second, the static file placement

1, static files placed, index.html placed in templates in other folders such as js, css folders, image folders, and so on static directory

SpringBoot jump to a static html page && static file placement

2, the path of html file modification

Use an absolute path similar forms, such as: /image/1.png, can not be written ../static/image/1.png

SpringBoot jump to a static html page && static file placement

Guess you like

Origin blog.51cto.com/doublelinux/2437039
Recommended