2框架struts2個人高效秘籍:分頁組合查詢easyui實現(xiàn)模塊管理,增刪改查【詩書畫唱】

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
? <display-name>J190802</display-name>
? <!-- struts2框架的配置 -->
? <filter>
? ? ? <filter-name>struts2</filter-name>
? ? ? <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
? </filter>
? <filter-mapping>
? ? ? <filter-name>struts2</filter-name>
? ? ? <url-pattern>/*</url-pattern>
? </filter-mapping>
? <welcome-file-list>
? ? <welcome-file>index.html</welcome-file>
? ? <welcome-file>index.htm</welcome-file>
? ? <welcome-file>index.jsp</welcome-file>
? ? <welcome-file>default.html</welcome-file>
? ? <welcome-file>default.htm</welcome-file>
? ? <welcome-file>default.jsp</welcome-file>
? </welcome-file-list>
</web-app>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? </head>
? ? <body>
? ? ? ? <h1 align="center">新增游戲</h1>
? ? ? ? <form id="addFrm" action="" method="post">
? ? ? ? ? ? <table align="center">
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td>游戲名稱:</td>
? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? <input name="g.gname" class="easyui-validatebox"?
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="required:true"?
? ? ? ? ? ? ? ? ? ? ? ? ? ? validType="length[6,30]"?
? ? ? ? ? ? ? ? ? ? ? ? ? ? invalidMessage="游戲名稱的長度必須在6到30位之間"
? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" />
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td>游戲類型:</td>
? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? <input name="g.gtype" class="easyui-combobox"
? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;"
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="valueField:'id',textField:'gtype',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? panelHeight:'auto',editable:false,url:'gm/loadTypeAc.action'" />
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td>游戲公司:</td>
? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? <input name="g.gcomp" class="easyui-validatebox"??
? ? ? ? ? ? ? ? ? ? ? ? ? ? validType="length[4,30]"?
? ? ? ? ? ? ? ? ? ? ? ? ? ? invalidMessage="游戲公司的長度必須在4到30位之間"
? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" />
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td>游戲年份:</td>
? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? <input name="g.gyear" class="easyui-numberbox"
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="min:1000,max:9999"
? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" />
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td colspan="2" align="center">
? ? ? ? ? ? ? ? ? ? ? ? <a hreff="javascript:saveGame();" class="easyui-linkbutton"
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="iconCls:'icon-save'">保存</a>
? ? ? ? ? ? ? ? ? ? ? ? <a hreff="javascript:clsWin();" class="easyui-linkbutton"
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="iconCls:'icon-cut'">取消</a>
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? </table>
? ? ? ? </form>
? ? </body>
</html>

{"total":2,"rows":[{"id":1,"gname":"WANGZHERONGYI","gtype":"MOB","gcomp":"TENCENT","gyear":2010}]}

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? </head>
? ? <body>
? ? ? ? <h1 align="center">修改游戲</h1>
? ? ? ? <form id="editFrm" action="" method="post">
? ? ? ? ? ? <!-- 選中的游戲的id存放在隱藏表單域 -->
? ? ? ? ? ? <input type="hidden" name="g.id" value="${g.id }"/>
? ? ? ? ? ? <table align="center">
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td>游戲名稱:</td>
? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? <input name="g.gname" class="easyui-validatebox"?
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="required:true"?
? ? ? ? ? ? ? ? ? ? ? ? ? ? validType="length[2,30]" value="${g.gname }"
? ? ? ? ? ? ? ? ? ? ? ? ? ? invalidMessage="游戲名稱的長度必須在6到30位之間"
? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" />
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td>游戲類型:</td>
? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? <input name="g.gtype" class="easyui-combobox"
? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" value="${g.gtype}"
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="valueField:'id',textField:'gtype',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? panelHeight:'auto',editable:false,url:'gm/loadTypeAc.action'" />
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td>游戲公司:</td>
? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? <input name="g.gcomp" class="easyui-validatebox"??
? ? ? ? ? ? ? ? ? ? ? ? ? ? validType="length[2,30]" value="${g.gcomp }"
? ? ? ? ? ? ? ? ? ? ? ? ? ? invalidMessage="游戲公司的長度必須在4到30位之間"
? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" />
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td>游戲年份:</td>
? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? <input name="g.gyear" class="easyui-numberbox"
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="min:1000,max:9999" value="${g.gyear }"
? ? ? ? ? ? ? ? ? ? ? ? ? ? style="width:180px;" />
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? <td colspan="2" align="center">
? ? ? ? ? ? ? ? ? ? ? ? <a hreff="javascript:editGame();" class="easyui-linkbutton"
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="iconCls:'icon-save'">保存</a>
? ? ? ? ? ? ? ? ? ? ? ? <a hreff="javascript:clsWin();" class="easyui-linkbutton"
? ? ? ? ? ? ? ? ? ? ? ? ? ? data-options="iconCls:'icon-cut'">取消</a>
? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? </table>
? ? ? ? </form>
? ? </body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? ? <head>
? ? ? ? <base hreff="<%=basePath%>">
? ? ? ? <title></title>
? ? ? ? <meta http-equiv="pragma" content="no-cache">
? ? ? ? <meta http-equiv="cache-control" content="no-cache">
? ? ? ? <meta http-equiv="expires" content="0">
? ? ? ? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
? ? ? ? <meta http-equiv="description" content="This is my page">
? ? ? ? <link rel="stylesheet" type="text/css" hreff="css/themes/default/easyui.css">
? ? ? ? <link rel="stylesheet" type="text/css" hreff="css/themes/icon.css">
? ? ? ? <script type="text/javascript" srcc="js/jquery.min.js"></script>
? ? ? ? <script type="text/javascript" srcc="js/jquery.easyui.min.js"></script>
? ? ? ? <!-- 語言漢化包 -->
? ? ? ? <script type="text/javascript" srcc="js/locale/easyui-lang-zh_CN.js"></script>
? ? ? ? <script type="text/javascript">
? ? ? ? ? ? function toAdd(){
? ? ? ? ? ? var url = 'add.jsp';
? ? $('#win').window({
? ? width : 700,//寬度
? ? height : 550,//高度
? ? title : '新增',
? ? hreff : url
? ? });
? ? $('#win').window('open');//打開窗體
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? function toEdit(){
? ? ? ? ? ? //獲取選中的行
? ? ? ? ? ? var row = $('#dg').datagrid('getSelected');
? ? ? ? ? ? var id = row.id;
? ? ? ? ? ? //判斷是否選中
? ? ? ? ? ? if(! row) {
? ? ? ? ? ? $.messager.alert("提示", "請選要修改的數(shù)據(jù)", "info");
? ? ? ? ? ? } else {
? ? ? ? ? ? var url = 'gm/toEditAc.action?g.id=' + id;
? ? ? ? $('#win').window({
? ? ? ? width : 700,//寬度
? ? ? ? height : 550,//高度
? ? ? ? title : '修改',
? ? ? ? hreff : url
? ? ? ? });
? ? ? ? $('#win').window('open');//打開窗體
? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? function doDelete(){
? ? ? ? ? ? //獲取選中的行
? ? ? ? ? ? var row = $('#dg').datagrid('getSelected');
? ? ? ? ? ? var id = row.id;
? ? ? ? ? ? //判斷是否選中
? ? ? ? ? ? if(! row) {
? ? ? ? ? ? $.messager.alert("提示", "請選要刪除的數(shù)據(jù)", "info");
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? //刪除二次確認(rèn)
? ? ? ? ? ? ? ? $.messager.confirm("提示", "確定刪除" + id + "的記錄嗎?",function(re) {
? ? ? ? ? ? ? ? //re為true就表示點擊了確定按鈕
? ? ? ? ? ? ? ? //re為false就表示點擊了取消按鈕
? ? ? ? ? ? ? ? if(re) {
? ? ? ? ? ? ? ? //提交ajax執(zhí)行刪除
? ? ? ? ? ? ? ? $.ajax({
? ? ? ? ? ? ? ? url: 'gm/deleteAc.action',
? ? ? ? ? ? ? ? type: 'POST',
? ? ? ? ? ? ? ? data: {
? ? ? ? ? ? ? ? 'g.id': id
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? success: function(data){
? ? ? ? ? ? ? ? var o = JSON.parse(data);
? ? ? ? ? ? ? ? if(o.ct > 0) {
? ? ? ? ? ? ? ? $.messager.alert("提示", "刪除成功!", "info");
? ? ? ? ? ? ? ? //刷新datagrid
? ? ? ? ? ? ? ? $('#dg').datagrid('reload');
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? $.messager.alert("提示", "刪除失?。?#34;, "info");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? }?
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? function clsWin(){
? ? ? ? ? ? $('#win').window('close');
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? //提交新增表單(在add.jsp頁面調(diào)用這個方法)
? ? ? ? ? ? //通過這種方式提交表單是沒有頁面跳轉(zhuǎn)
? ? ? ? ? ? function saveGame(){
? ? ? ? ? ? //手動提交表單
? ? ? ? ? ? $('#addFrm').form('submit',{
? ? ? ? ? ? url: 'gm/addAc',
? ? ? ? ? ? onSubmit: function(){//表單驗證
? ? ? ? ? ? //this就是指當(dāng)前的表單
? ? ? ? ? ? //調(diào)用表單驗證的方法
? ? ? ? ? ? var isValid = $(this).form('validate');
? ? ? ? ? ? ? ? //if(!isValid) {
? ? ? ? ? ? ? ? // alert('驗證不通過')
? ? ? ? ? ? ? ? //}
? ? ? ? ? ? ? ? return isValid;
? ? ? ? ? ? },
? ? ? ? ? ? success: function(data){//表單提交成功以后執(zhí)行的回調(diào)函數(shù)
? ? ? ? ? ? var o = JSON.parse(data);
? ? ? ? ? ? if(o.ct > 0) {
? ? ? ? ? ? $.messager.alert("提示", "新增成功", "info");
? ? ? ? ? ? //刷新datagrid
? ? ? ? ? ? $('#dg').datagrid('reload');
? ? ? ? ? ? //關(guān)閉窗體
? ? ? ? ? ? $('#win').window('close');
? ? ? ? ? ? } else {
? ? ? ? ? ? $.messager.alert("提示", "新增失敗", "info");
? ? ? ? ? ? }
? ? ? ? ? ?
? ? ? ? ? ? }
? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? function editGame(){
? ? ? ? ? ? $('#editFrm').form('submit',{
? ? ? ? ? ? url: 'gm/editAc.action',
? ? ? ? ? ? onSubmit: function(){
? ? ? ? ? ? var isValid = $(this).form('validate');
? ? ? ? ? ? return isValid;
? ? ? ? ? ? },
? ? ? ? ? ? success: function(data){
? ? ? ? ? ? var o = JSON.parse(data);
? ? ? ? ? ? if(o.ct > 0) {
? ? ? ? ? ? $.messager.alert("提示", "修改成功", "info");
? ? ? ? ? ? //刷新datagrid
? ? ? ? ? ? $('#dg').datagrid('reload');
? ? ? ? ? ? //關(guān)閉窗體
? ? ? ? ? ? $('#win').window('close');
? ? ? ? ? ? } else {
? ? ? ? ? ? $.messager.alert("提示", "修改失敗", "info");
? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? function doQuery(){
? ? ? ? ? ? //獲取所有的搜索條件
? ? ? ? ? ? var gname = $('#q_gname').val();
? ? ? ? ? ? var gtype = $('#q_gtype').combobox('getValue');
? ? ? ? ? ? var gcomp = $('#q_gcomp').val();
? ? ? ? ? ? var starYear = $('#q_startYear').val();
? ? ? ? ? ? var endYear = $('#q_endYear').val();
? ? ? ? ? ? //執(zhí)行查詢
? ? ? ? ? ? $('#dg').datagrid('reload',{
? ? ? ? ? ? 'g.gname': gname,
? ? ? ? ? ? 'g.gtype': gtype,
? ? ? ? ? ? 'g.gcomp': gcomp,
? ? ? ? ? ? 'g.startYear': starYear,
? ? ? ? ? ? 'g.endYear': endYear
? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? </script>
? ? </head>
? ? <body>
? ? ? ? <table id="dg" class="easyui-datagrid" title="游戲管理模塊"?
? ? ? ? ? ? style="width:1000px;height:450px"
data-options="singleSelect:true,collapsible:true,
url:'gm/ldAllAc.action',method:'get',pagination:true,
pageList:[3,5,7,10,15],pageSize:5,toolbar:'#tb'">
<thead>
<tr>
<th data-options="field:'id',width:80">游戲ID</th>
<th data-options="field:'gname',width:100">游戲名稱</th>
<th data-options="field:'gtype',width:80,align:'right'">游戲類型</th>
<th data-options="field:'gcomp',width:80,align:'right'">游戲公司</th>
<th data-options="field:'gyear',width:250">游戲年份</th>
</tr>
</thead>
</table>
<!-- 工具欄 -->
<div id="tb" style="padding:5px;height:auto">
? ? <!-- 按鈕工具欄 -->
? ? <div style="margin-bottom:5px">
? ? ? ? <a hreff="javascript:toAdd();" class="easyui-linkbutton"?
? ? ? ? ? ? iconCls="icon-add" plain="true" title="新增"></a>
<a hreff="javascript:toEdit();" class="easyui-linkbutton"?
? ? iconCls="icon-edit" plain="true" title="修改"></a>
<a hreff="javascript:doDelete();" class="easyui-linkbutton"?
? ? iconCls="icon-remove" plain="true" title="刪除"></a>
? ? </div>
? ? <!-- 查詢工具欄 -->
? ? <div>
? ? ? ? <p>
? ? ? ? <input id="q_gname" placeholder="請輸入游戲詞條"
? ? ? ? ? ? class="easyui-validatebox" style="width:140px;" />
? ? ? ? <label>游戲類型:</label>
? ? ? ? <input id="q_gtype" class="easyui-combobox"
? ? ? ? ? ? ? ? ? ? style="width:180px;"
? ? ? ? ? ? ? ? ? ? data-options="valueField:'id',textField:'gtype',
? ? ? ? ? ? ? ? ? ? ? ? panelHeight:'auto',editable:false,url:'gm/loadTypeAc.action'" />
? ? ? ? ? ? ? ? <input id="q_gcomp" placeholder="請輸入公司詞條"
? ? ? ? ? ? class="easyui-validatebox" style="width:140px;" />
? ? ? ? </p>
? ? ? ? <p>
? ? ? ? <label>游戲年份:</label>
? ? ? ? <input id="q_startYear" class="easyui-numberbox"
? ? ? ? ? ? style="width:120px;" data-options="min:1000,max:9999" />
? ? ? ? <label>到</label>
? ? ? ? <input id="q_endYear" class="easyui-numberbox"
? ? ? ? ? ? style="width:120px;" data-options="min:1000,max:9999" />
? ? ? ? <a hreff="javascript:doQuery();" class="easyui-linkbutton"?
? ? ? ? ? ? ? ? ? ? ? ? iconCls="icon-search"></a>
? ? ? ? </p>
? ? </div>
</div>
<!-- 彈出窗體 -->
<div id="win" class="easyui-window"
data-options="modal:true,closed:true,iconCls:'icon-save', top: 20,
? ? minimizable: false,maximizable: false,collapsible: false,left: 100">
? ? </div>??
? ? </body>
</html>

例子 END
例子運行效果 START



