springboot访问html静态等资源

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_42614414/article/details/98754289

1、将html放在static文件目录下,可以直接访问,无需任何配置

在这里插入图片描述

2 、springboot如何访问static之外的静态资源

1、pom导入jar包

<!--导入html依赖-->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、application.yml

  thymeleaf:
    prefix: classpath:/templates/
    cache: true
    mode: HTML5
    encoding: UTF-8
    servlet:
      content-type: text/html --可以设置,也可以不设置,因为这是系统默认配置

3、编写controller

如果你想返回视图,也就是一个html页面,请使用controller注解
如果你想返回json数据,请使用restController注解

@Controller
public class TestController {
    @RequestMapping("/index")
    public String page(){
        System.out.println("hello shiro");
        return "shiro";
    }
}
前段输入http://localhost:8081/index  就会去访问/templates/shiro.html页面

在这里插入图片描述

4、springboot访问jsp页面

有空在写

猜你喜欢

转载自blog.csdn.net/qq_42614414/article/details/98754289