先看下效果圖:
===========================================================================================================================================
1.1前端html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> <title>全民發布</title> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/> <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css"/> <link rel="stylesheet" href="/bootstrap/css/bootstrap-table.css"/> <link rel="stylesheet" href="/bootstrap/css/bootstrap-editable.css"/> <link rel="stylesheet" href="/bootstrap/css/fileinput.min.css"/> <link rel="stylesheet" href="/bootstrap/css/font-awesome.min.css"/> <link rel="stylesheet" href="/bootstrap/css/ionicons.min.css"/> <link rel="stylesheet" href="/plugins/datatables/dataTables.bootstrap.css"/> <link rel="stylesheet" href="/dist/css/AdminLTE.min.css"/> <link rel="stylesheet" href="/dist/css/skins/_all-skins.min.css"/> </head> <body class="hold-transition skin-blue sidebar-mini"> <div th:replace="fragment/header :: header"></div> <div th:replace="fragment/aside :: aside"></div> <div class="wrapper"> <div class="content-wrapper"> <section class="content-header"> <h1> 系統管理 <small>幻燈片管理</small> </h1> </section> <section class="content"> <div class="row"> <div class="panel-body" style="padding-bottom:0px;"> <div id="toolbar" class="btn-group"> <button id="btn_add" type="button" class="btn btn-success" onclick="btn_add()"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增 </button> <button id="remove" class="btn btn-danger" > <i class="glyphicon glyphicon-remove"></i> 刪除 </button> </div> <div class="box"> <!-- /.box-header --> <div class="box-body"> <table id="tb_customer" data-response-handler="responseHandler"> </table> </div> </div> </div> <!-- /.col --> </div> <!-- /.row --> </section> <!-- /.content --> </div> <div th:replace="system/slider-form:: slider-form"></div> </div> <!-- ./wrapper --> <!-- jQuery 2.2.3 --> <script src="/plugins/jQuery/jquery-2.2.3.min.js"></script> <!-- Bootstrap 3.3.6 --> <script src="/bootstrap/js/bootstrap.min.js"></script> <script src="/bootstrap/js/bootstrap-table.js"></script> <script src="/bootstrap/js/bootstrap-table-zh-CN.js"></script> <script src="/bootstrap/js/bootstrap-table-editable.js"></script> <script src="/bootstrap/js/bootstrap-editable.js"></script> <script src="/bootstrap/js/fileinput.min.js"></script> <!-- DataTables --> <script src="/plugins/datatables/jquery.dataTables.min.js"></script> <script src="/plugins/datatables/dataTables.bootstrap.min.js"></script> <!-- SlimScroll --> <script src="/plugins/slimScroll/jquery.slimscroll.min.js"></script> <!-- FastClick --> <script src="/plugins/fastclick/fastclick.js"></script> <!-- AdminLTE App --> <script src="/dist/js/app.min.js"></script> <!-- AdminLTE for demo purposes --> <script src="/dist/js/demo.js"></script> <script type="text/javascript" src="/js/jquery.cookie.js"></script> <script type="text/javascript" src="/lib/layer/1.9.3/layer.js"></script> <!-- page script --> <script>var TableInit = function () { var oTableInit = new Object(); //初始化Table oTableInit.Init = function () { $('#tb_customer').bootstrapTable({ url: '/slider-data', //請求后台的URL(*) method: 'get', //請求方式(*) toolbar: '#toolbar', //工具按鈕用哪個容器 striped: true, //是否顯示行間隔色 cache: false, //是否使用緩存,默認為true,所以一般情況下需要設置一下這個屬性(*) pagination: true, //是否顯示分頁(*) sortable: false, //是否啟用排序 sortOrder: "asc", //排序方式 queryParams: oTableInit.queryParams,//傳遞參數(*) sidePagination: "server", //分頁方式:client客戶端分頁,server服務端分頁(*) pageNumber:1, //初始化加載第一頁,默認第一頁 pageSize: 10, //每頁的記錄行數(*) pageList: [10], //可供選擇的每頁的行數(*) search: true, //是否顯示表格搜索,此搜索是客戶端搜索,不會進服務端,所以,個人感覺意義不大 strictSearch: true, showColumns: true, //是否顯示所有的列 showRefresh: true, //是否顯示刷新按鈕 minimumCountColumns: 2, //最少允許的列數 clickToSelect: true, //是否啟用點擊選中行 height: 500, //行高,如果沒有設置height屬性,表格自動根據記錄條數覺得表格高度 uniqueId: "id", //每一行的唯一標識,一般為主鍵列 showToggle:true, //是否顯示詳細視圖和列表視圖的切換按鈕 cardView: false, //是否顯示詳細視圖 detailView: false, //是否顯示父子表onEditableSave columns: [{ checkbox: true }, { field: 'id', title: 'id' }, { field: 'thumbAUrl', title: '圖片鏈接', formatter:function(value,row,index){ return '<a href="'+row.thumbAUrl+'" target="_blank">'+row.thumbAUrl+'</a>' } }, { field: 'spaceId', title: '位置', formatter:function(value,row,index){ if(row.spaceId==1){ return 'home'; }else if(row.spaceId==2){ return 'task'; }else{ return row.spaceId; } } }, { field: 'type', title: '類型', formatter:function(value,row,index){ if(row.type==1){ return '點擊無動作'; }else if(row.type==2){ return '任務'; }else if(row.type==3){ return 'activity跳轉'; }else { return '有html落地頁'; } } } , { field: 'thirdAction', title: '動作' } , { field: 'status', title: '狀態', editable: { type: 'select', title: '狀態', source:[{value:"1",text:"啟用"},{value:"0",text:"禁用"}] } } , { field: 'ord', title: '排序', editable: true } , { field: 'operate', title: '操作', align: 'center', events: operateEvents, formatter: operateFormatter } ], onEditableSave: function (field, row, oldValue, $el) { $.ajax({ type: "post", url: "/editSliderState", data: { strJson: JSON.stringify(row) }, success: function (data, status) { if (status == "success") { layer.alert('編輯成功'); } }, error: function () { alert("Error"); }, complete: function () { } }); } }); }; </script> </body> </html>
1.2 java
@RequestMapping(value = "/editSliderState", method = RequestMethod.POST) @ResponseBody public JSONObject editSliderState(@RequestParam("strJson") String json,HttpServletRequest request) { JSONObject jsons = new JSONObject(); JSONObject obj = JSONObject.parseObject(json); Integer id = obj.getInteger("id"); Integer status =obj.getInteger("status"); Integer ord=obj.getInteger("ord"); try { urlService.updateSliderStatus(id,status,ord); logService.insertOpreateLog("修改了幻燈片:id是"+obj.getInteger("id"), request); jsons.put("success", true); } catch (Exception e) { } return jsons; }