easyUI+springMVC的DataGrid-demo

本文介绍了如何在SpringMVC框架中正确配置静态资源映射,以解决访问HTML页面时出现的HTTPStatus404错误。同时,还详细说明了如何引入EasyUI库并正确配置其资源路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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'}    
        ]]    
    }); 
})

 

转载于:https://www.cnblogs.com/liaozs/p/5727734.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值