Spring+SpringMVC+mybatis+easyui整合实例-----easyUI界面部分

本文介绍了如何使用 EasyUI 的 DataGrid 组件展示学生信息,并通过添加分页、行号等功能进一步完善表格。提供了 Java 后端实现代码及 HTML 页面配置。

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

首先简单介绍下easyui的使用。 

我们从datagrid表格入手,先显示一个简单的表格来说明一下easyui的使用。后面再加一个功能完整的表格

首先方法写好,还是使用之前的例子,没看过之前博客的可以翻一下。 
StudentDaoIF.java

@Select("select * from student") 
@Results({ @Result(column = "id" , property = "id"), @Result(column = "name" , property = "name"), @Result(column =  "password" , property = "password") }) 
public List<Student> selectAllStudents();

StudentServiceImpl.java:

@Override
public List<Student> selectAllStudents() { 
return dao.selectAllStudents(); 
}

StudentController.java

 @RequestMapping("/ShowStudents.do")
 @ResponseBody 
 public Map showStudents() throws Exception{ 
 Map map=new HashMap(); 
 List<Student> students = dao.selectAllStudents();
 map.put("rows",students); 
 map.put("total", 20); 
 return map; 
  }

注:这里说明一下,easyui的datagrid使用必须要返回两个字段:rows和total,分别表示数据和总条数

页面datagird.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
datagird.html</title>
<link rel="stylesheet" type="text/css" href="../jquery-easyui-1.4.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../jquery-easyui-1.4.3/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../jquery-easyui-1.4.3/demo/demo.css">
<script type="text/javascript" src="../jquery-easyui-1.4.3/jquery.min.js"></script>
<script type="text/javascript" src=="../jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<script type="text/javascript">
$(function(){ $("#dg").datagrid({ 
url:"../ShowStudents.do", columns:[[ 
{field:'id',title:'id',width:100}, 
{field:'name',title:'name',width:100},
{field: 'password',title:'password',width:100}
]] }); }); 
</script>
</head>
<body>
<table id="dg"></table>
</body>
</html>

注:这几个css、js文件是使用easyui必须导入的。 
最后显示入下: 
这里写图片描述

当然这只是个最简单的表格,我们可以添加参数让表格更加完整些。像下面这样:


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>datagird.html</title>
<link rel="stylesheet" type="text/css" href="../jquery-easyui-1.4.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../jquery-easyui-1.4.3/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../jquery-easyui-1.4.3/demo/demo.css">
<script type="text/javascript" src="../jquery-easyui-1.4.3/jquery.min.js"> </script>
<script type="text/javascript" src="../jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<script type="text/javascript"> $(function(){ $("#dg").datagrid({
url:"../ShowStudents.do", columns:[[ {field:'id',title:'id',width:100},
{field:'name',title:'name',width: 100}, 
{field:'password',title:'password',width:100} ]], 
toolbar:'#toolbar', //表格菜单 
loadMsg:'嗖 ----正在火速加载中 -------------', //加载提示
pagination:"true, //显示分页工具栏
rownumbers:true, //显示行号列 
singleSelect:true,//是允许选择一行
queryParams:{ //在请求数据是发送的额外参数,如果没有则不用谢
 name:'easyui', hhh:'aa'} }); }); </script>
 </head>
 <body>
 <table id=dg">
 </table>
 <div id="toolbar">
 <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a>
 <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">编辑</a>
 <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
 </div>
 </body>
 </html>

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值