Springboot的静态资源文件夹是项目的resource目录下的static文件夹,并且Springboot会默认开放静态资源文件,不需要做什么设置
想要访问静态资源文件需要先导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
在resources下的static中放入图片
目录结构如下,运行项目
用浏览器访问http://localhost:8080/1.jpg就可以直接拿到
访问html文件,需要在resources下的template文件夹下方应该html文件,并且写一个controller类
package com.example.springbootstudentsystem;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//RestController是返回字符串,Controller返回拼接的模板
@Controller
public class test {
@RequestMapping("/test")
public String hello(){
return "test";
}
}