首页 > IT职业 > IT生活 > SpringBoot使用WebJars
本人主要做的是java,但是从第一份工作开始,就一直在做一个写前端又写后端的程序员,相信很多朋友和我一样,不仅要会后台代码,还要懂得很多的前端代码,例如javascipt和css样式。
webjars官网:传送门
本文就为大家简单介绍一下SpringBoot如何结合前端代码。
SpringBoot结合前端有很多种方法,比如在static里面直接加入css或js,又或者引入webjars,以jar包的形式加入项目,本文就是简单介绍一下这种方式。
话不多说,直接引入代码,还是新建一个SpringBoot Web项目。然后在pom文件引入webjars的jar,pom文件代码如下:
4.0.0 com.dalaoyang springboot_webjars 0.0.1-SNAPSHOT jar springboot_webjars springboot_webjars org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE <!-- lookup parent from repository -->UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools runtime org.springframework.boot spring-boot-starter-test test <!-- 引用bootstrap -->org.webjars bootstrap 3.3.7-1 <!-- 引用jquery -->org.webjars jquery 3.1.1 org.springframework.boot spring-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/ ,如需转载,请注明出处,否则将追究法律责任。