springboot前台不分离引用js【我】

下面所有配置都是在springboot如下版本下的,其他版本可能会有不同

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

 

 

一、

pom中引入jar包

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

 

 

 

二、

静态资源主页面放在 resources下的 templates里,其他js等放在stasic下面(这里新建了一个js下级目录)

 

三、yml配置文件里要配置

spring:
mvc:
static-path-pattern: /**
web:
resources:
static-locations: classpath:/static/

 

 

 

四、 html中直接使用写法(/js 前面没有 / 也行)

<script src="/js/jquery-3.6.0.js"></script>

 

 

五、Controlller代码

@GetMapping(value = {"/"})
public String index(){
return "index";
}

 

 

六、效果:

 

posted @ 2021-10-13 09:19  戈博折刀  阅读(574)  评论(0编辑  收藏  举报