问题场景 :为什么配置context-path=/可以访问到js css 配置成context-path=/app没办法访问到js和css?
遇到这个问题该怎么办?直接上答案
使用thymeleaf模板,动态获取上下文路径
1.声明
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
2.引入
<link rel="stylesheet" th:href="@{/css/base.css?v=1}"/>
<script th:src="@{/javascript/jquery-1.8.0.min.js}" type="text/javascript"></script>
问题又来了,js文件中如何引入项目名
看这里
1.新建config.js文件
window.globalConfig = {
context_path : '/app'
}
2.引入config.js
<script th:src="@{/javascript/config.js}" type="text/javascript"></script>
3.使用
function login(username, password) {
$.ajax({
type: "POST",
url: window.globalConfig.context_path+"/login",
data: {'curr':curr,'limit':limit},
dataType: "json",
success: function (data) {
if (data.code == 200) {
}
},
error: function () {
layer.alert('网络异常');
}
})
}
那问题又来了,<a>标签中链接如何引入项目名?
想不想联系到我?想?不想?到底想不想?不想,不想就算了,关了页面走吧,我的QQ群:578060039 也不告诉你了
打完收工
网友评论