博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring使用webjar
阅读量:4337 次
发布时间:2019-06-07

本文共 3126 字,大约阅读时间需要 10 分钟。

注意事项

这玩意很简单,但是我们第一次搞就是搞不成功,为什么呢?因为我们都用的是idea或者eclipse编译。webjar只能在maven上才能打包,所以在使用时,记得maven-clean和maven-package!

先丢代码地址

https://gitee.com/a247292980/lgp20151222

再丢pom.xml

4.0.0
com.lgp
webjar
0.0.1-SNAPSHOT
jar
webjar
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
1.5.10.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.webjars
bootstrap
3.3.7-1
org.webjars
jquery
3.1.1
org.springframework.boot
spring-boot-maven-plugin

最后丢目录结构

WebjarApplication

没动过

Demo.html

            WebJars Demo    
× Hello,
WebJars!

 高级技能

/** * Created by IntelliJ IDEA. * User: a247292980 * Date: 2017/08/14  * * webjars-locator 包的作用是处理WebJars,省略 webjar 的版本。 * 比如对于请求 http://localhost:8080/webjars/jquery/3.1.0/jquery.js省略版本号 3.2.1 * 直接使用http://localhost:8080/webjarslocator/jquery/jquery.js也可访问。 * 其实吧,webjar,webjarslocator都耗系统性能的!!!!! **/@Controllerpublic class WebJarController {    private final WebJarAssetLocator assetLocator = new WebJarAssetLocator();    @ResponseBody    @RequestMapping("/webjarslocator/{webjar}/**")    public ResponseEntity locateWebjarAsset(@PathVariable String webjar, HttpServletRequest request) {        try {            String mvcPrefix = "/webjarslocator/" + webjar + "/";            String mvcPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);            String fullPath = assetLocator.getFullPath(webjar, mvcPath.substring(mvcPrefix.length()));            return new ResponseEntity(new ClassPathResource(fullPath), HttpStatus.OK);        } catch (Exception e) {            return new ResponseEntity(HttpStatus.NOT_FOUND);        }    }}

 

转载于:https://www.cnblogs.com/ydymz/p/8404145.html

你可能感兴趣的文章
64位Linux下使用QQ
查看>>
使用 FOR XML PATH 合并SQL Server查询结果的重复行
查看>>
jQ 插件 iscroll.js
查看>>
MVC 组件
查看>>
蓝桥杯:安慰奶牛(最小生成树)
查看>>
源码安装git工具,显示/usr/local/lib64/libcrypto.a(dso_dlfcn.o) undefined reference to `dlopen'...
查看>>
SVN中各种符号箭头含义
查看>>
关于现在手上做的项目的数据库设计思考
查看>>
Windows Azure Cloud Service (27) 在Windows Azure发送邮件(上)
查看>>
asp.net ajax控件工具集 AutoCompleteExtender控件
查看>>
使用Core Animation对象来实现动画
查看>>
Bulk Operations Using Oracle Data Provider for .NET (ODP.NET) 转载
查看>>
Linux入门(9)——Ubuntu16.04安装flash player
查看>>
醒悟人生
查看>>
用DOS命令来运行Java代码
查看>>
高精度乘法
查看>>
试试博客园的markdown编辑器
查看>>
【bzoj5082】弗拉格 矩阵乘法
查看>>
【uoj#225】[UR #15]奥林匹克五子棋 构造
查看>>
【bzoj5084】hashit 广义后缀自动机+树链的并+STL-set
查看>>