SpringBoot跳转到静态html页面&&静态文件放置位置

SpringBoot跳转到静态html页面&&静态文件放置位置

一、SpringBoot跳转到静态html页面

1、在pom.xml中添加spring-boot-starter-thymeleaf。

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

2、在templates下建立a.html文件,新建qiu文件夹,并且在qiu文件夹中创建b.html

SpringBoot跳转到静态html页面&&静态文件放置位置

10年的齐河网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整齐河建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“齐河网站设计”,“齐河网站推广”以来,每个客户项目都认真落实执行。

a.html内容如下:

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

b.html文件内容如下:

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

3、在controller中写一个返回该页面的controller【此时不能使用@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/2 和 http://127.0.0.1:502/1/3

SpringBoot跳转到静态html页面&&静态文件放置位置

SpringBoot跳转到静态html页面&&静态文件放置位置

二、静态文件放置位置

1、静态文件放置为,index.html放置在templates中,其他的如js文件夹、css文件夹、image文件夹等放在static目录下

SpringBoot跳转到静态html页面&&静态文件放置位置

2、html文件中的路径修改
使用类似绝对路径的形式,如:/image/1.png,不能写成../static/image/1.png

SpringBoot跳转到静态html页面&&静态文件放置位置

文章标题:SpringBoot跳转到静态html页面&&静态文件放置位置
转载注明:https://www.cdcxhl.com/article6/jopiig.html

成都网站建设公司_创新互联,为您提供品牌网站设计域名注册软件开发Google自适应网站做网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设