ITPub博客

首页 > IT职业 > IT生活 > SpringBoot使用WebJars

SpringBoot使用WebJars

IT生活 作者:silverhoof 时间:2021-09-09 09:34:06 0 删除 编辑

本人主要做的是java,但是从第一份工作开始,就一直在做一个写前端又写后端的程序员,相信很多朋友和我一样,不仅要会后台代码,还要懂得很多的前端代码,例如javascipt和css样式。

webjars官网:传送门

本文就为大家简单介绍一下SpringBoot如何结合前端代码。

SpringBoot结合前端有很多种方法,比如在static里面直接加入css或js,又或者引入webjars,以jar包的形式加入项目,本文就是简单介绍一下这种方式。

话不多说,直接引入代码,还是新建一个SpringBoot Web项目。然后在pom文件引入webjars的jar,pom文件代码如下:

4.0.0com.dalaoyangspringboot_webjars0.0.1-SNAPSHOTjarspringboot_webjarsspringboot_webjarsorg.springframework.bootspring-boot-starter-parent1.5.9.RELEASE<!-- lookup parent from repository -->UTF-8UTF-81.8org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-devtoolsruntimeorg.springframework.bootspring-boot-starter-testtest<!-- 引用bootstrap -->org.webjarsbootstrap3.3.7-1<!-- 引用jquery -->org.webjarsjquery3.1.1org.springframework.bootspring-boot-maven-plugin

然后我们观察一下项目的依赖jar包,依赖中就有了bootstrap.jar和jquery.jar

图片描述

然后在src/main/resources/static文件下新建index.html,代码如下:





Dalaoyang


× Hello, Dalaoyang!

至此配置已经结束,启动项目,访问http://localhost:8888/

图片描述

至此SpringBoot结合WebJars成功就完成。

源码下载 :大老杨码云

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1528/viewspace-2810762/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    81
  • 访问量
    903