访问页面采用后端代码来实现:
导入jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
后端代码实现:
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 页面加载
*/
@Controller
public class PageController {
@RequestMapping("/first")
public String firstPage(){
return "/first";
}
}
注意是@Controller
之后要开开新信息的访问页面就行了
然后就发生问题了,静态资源全部访问不到,但是页面中页有路径啊啊啊啊!
解决办法(在配置文件中添加):
# 应该以什么样的路径来访问静态资源,这表示只有静态资源的访问路径为/static/ 时才会处理(如http://localhost:8080/static/css/base.css)
spring.mvc.static-path-pattern=/static/**
#用于告诉Spring Boot应该在何处查找静态资源文件,查找文件时会依赖于配置的先后顺序依次进行
spring.resources.static-locations=classpath:/static,classpath:/public,classpath:/resources,classpath:/META-INF/resources
解决