问题描述:最近在开发SpringBoot项目时,使用了freemarker作为模板引擎,但此时出现问题,html文件无法引用js库,会报No mappring found for HttpRequest with URI ...
原因:使用模板后,js库的引用要使用绝对路径,不能使用相对路径。
解决方法:
SpringBoot2.0下,yml文件增加
spring:
mvc:
static-path-pattern: /static/** #静态资源路径
freemarker:
request-context-attribute: req
html文件引用js库时,路径名如下
<script type="text/javascript" src="${req.contextPath}/static/plugin/jquery-easyui-1.5.5.4/jquery.min.js"></script>
req即为前面yml文件的设置。freemarker的其他设置不再赘述。