• 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";
    }

    六、效果:

  • 相关阅读:
    Shell编程——基于IBM培训教程的总结
    flex上下固定中间滚动布局
    exe 转服务
    itextcsharp使用
    devices detect
    [转]Java api 全集 【API JDK1.6中文版】
    JavaScript 项目优化总结
    服务程序打包
    knockoutjs
    C#压缩《收藏》
  • 原文地址:https://www.cnblogs.com/libin6505/p/15400614.html
Copyright © 2020-2023  润新知