zoukankan      html  css  js  c++  java
  • 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";
    }

    六、效果:

  • 相关阅读:
    滚动图片
    Iframe自动适应高度
    我的生活,我的精彩!
    静下心来
    写给关心我的人
    关于考研
    按时间自动刷新页面
    破除网页鼠标右键禁用的十大绝招
    DotNetNuke 皮肤制作白皮书
    WollOp
  • 原文地址:https://www.cnblogs.com/libin6505/p/15400614.html
Copyright © 2011-2022 走看看