&&静的ファイルの配置静的なHTMLページにジャンプSpringBoot

&&静的ファイルの配置静的なHTMLページにジャンプSpringBoot

、SpringBootは、静的なHTMLページにジャンプ

1、のpom.xmlに春ブート・スターター・thymeleafを追加します。

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

2.テンプレートで新しい秋のフォルダをa.htmlファイルを確立し、秋にフォルダを作成しb.html

&&静的ファイルの配置静的なHTMLページにジャンプSpringBoot

次のようにa.htmlを読み取ります。

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

次のようにb.html文書が読み取ります。

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

図3に示すように、コントローラのコントローラこの時点で戻すためにページを書き込むには、[それ以外の場合は、文字列が返され、@RestController】使用することができません

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、それぞれ、ブラウザの訪問アクセスするhttp://127.0.0.1:502/1/2http://127.0.0.1:502/1/3を

&&静的ファイルの配置静的なHTMLページにジャンプSpringBoot

&&静的ファイルの配置静的なHTMLページにジャンプSpringBoot

第二に、静的なファイルの配置

1は、配置静的ファイルは、index.htmlを、このような静的なディレクトリにそうJS、CSSのフォルダ、画像フォルダ、およびなど他のフォルダにテンプレートに配置されました

&&静的ファイルの配置静的なHTMLページにジャンプSpringBoot

2、htmlファイルの変更のパス

/image/1.png、../static/image/1.png書き込むことができない次のような同様の形態は、絶対パスを使用

&&静的ファイルの配置静的なHTMLページにジャンプSpringBoot

おすすめ

転載: blog.51cto.com/doublelinux/2437039