DataGrid
(一)、搭建springMVC;
错误:无法访问HTML页面,HTTP Status 404-
原因:springMVC拦截了静态资源的访问
解决方案:方案①:(web.xml下)<servlet-mapping><servlet-name>jsp</servlet-name><url-pattern>*.html</url-pattern></servlet-mapping>
方案②:(springMVC.xml 下)<mvc:resources location="/" mapping="/**" />
(二)、加入easyUI:将解压后的easyui目录copy到WebContent目录下,并新建js目录、css目录
1、文件头:方式一:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../css/admin-index.css">
</head>
<body>
<table id="dg"></table>
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../js/admin-index.js"></script>
<script type="text/javascript" src="../easyui/locale/easyui-lang-zh_CN.js"></script>
</body>
</html>
错误:确定路径没错,但界面一直显示不出来。
原因:springMVC拦截了静态资源的访问(PS:如果springMVC的配置不拦截则不会报错,比如:<url-pattern>/*.do</url-pattern>)
解决方案:
<!-- 静态资源访问 -->
<mvc:resources location="/jquery-easyui/themes/" mapping="/jquery-easyui/themes/**"/>
<mvc:resources location="/jquery-easyui/" mapping="/jquery-easyui/**"/>
<mvc:resources location="/jquery-easyui/locale/" mapping="/locale/**" />
2、js的admin-index.js:
/**
*
*/
$(function(){
$('#dg').datagrid({
url:'',
pagination:'ture',
columns:[[
{field:'id',title:'ID',width:100},
{field:'name',title:'用户名',width:100},
{field:'age',title:'年龄',width:100,align:'right'}
]]
});
})