日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

EasyUI后台管理系统

發(fā)布時(shí)間:2023/12/9 windows 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 EasyUI后台管理系统 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目錄

1.?引入EasyUI文件

2. 網(wǎng)站首頁(yè)布局?

2.1 前端代碼

2.2 Servlet代碼?

2.3 dao層接口代碼

2.4 dao層實(shí)現(xiàn)類(lèi)代碼

2.5 biz層接口代碼

2.6 biz層實(shí)現(xiàn)類(lèi)代碼?

3. 書(shū)本展示模塊?

展示全部書(shū)本?and 模糊查詢(xún)

增加書(shū)本

編輯書(shū)本?

刪除書(shū)本?

3.1 前端代碼

3.2 js代碼

3.3 點(diǎn)擊編輯or增加按鈕打開(kāi)的頁(yè)面?

3.4 查詢(xún)and模糊查詢(xún)Servlet代碼?

3.5 增加書(shū)本Servlet代碼

3.6 編輯書(shū)本Servlet代碼

3.7 刪除書(shū)本Servlet代碼

3.8 dao層接口代碼

3.9 dao層實(shí)現(xiàn)類(lèi)代碼

?4.0 biz層接口代碼

?4.1 biz層實(shí)現(xiàn)類(lèi)代碼


1.?引入EasyUI文件

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!-- 保存項(xiàng)目名 --> <% request.setAttribute("cxt", request.getContextPath()); %> <!-- 保存js項(xiàng)目名 --> <script type="text/javascript"> var cxt="${cxt}"; </script> <!-- 引入EasyUI文件 --> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/js/jquery-easyui-1.5.5.2/themes/default/easyui.css"> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/js/jquery-easyui-1.5.5.2/themes/icon.css"> <script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery-easyui-1.5.5.2/jquery.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery-easyui-1.5.5.2/jquery.easyui.min.js"></script>

2. 網(wǎng)站首頁(yè)布局?

2.1 前端代碼

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <!-- 引入文件 --> <%@ include file="head.jsp" %> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>平臺(tái)首頁(yè)</title> <script type="text/javascript">$(function(){/* 給樹(shù)形菜單添加數(shù)據(jù) */$('#myUl').tree({ url: cxt+"/queryModuleServlet.do",/* 給樹(shù)標(biāo)簽添加雙擊 */onDblClick: function(node){/* 判斷如果是父標(biāo)簽就不增加 */var nodes = $('#myUl').tree('getChildren', node.target);// 獲取未選擇節(jié)點(diǎn)if(nodes<=0){/* 判斷是否重復(fù) */var index = $('#myTb').tabs('exists',node.text);if(!index){/* 增加表格 */$('#myTb').tabs('add',{ title:node.text, content:'<iframe src='+cxt+'/'+node.url+' frameborder=0px style="width: 100%; height: 100%;"></iframe>', //內(nèi)容、跳轉(zhuǎn)指定的頁(yè)面closable:true, }); }else{//不存在$('#myTb').tabs('select',node.text);}}}}); }) </script> </head> <body class="easyui-layout"> <!-- 面板 --><div data-options="region:'north',title:'上',split:true" style="height:100px;"><center><h1 style="font-family: '華文行楷'">蔣明輝工作室后臺(tái)管理</h1></center></div> <div data-options="region:'south',title:'下',split:true" style="height:100px;"><h2>?所有權(quán)限歸蔣明輝工作室</h2></div> <div data-options="region:'west',title:'左',split:true" style="width:200px;"><!-- 列表 --><ul id="myUl" class="easyui-tree"> </ul> </div> <div data-options="region:'center',title:'中間 '" style="padding:5px;background:#eee;"><div id="myTb" class="easyui-tabs" style="width:100%;height:100%;"> <div title="首頁(yè)" style="padding:0px;display:none;" > <img style="width:100%;height:100%;" title="我好喜歡你" alt="加載失敗" src="${cxt }/static/images/6.webp"></div> </div> </div> </body> </html>

2.2 Servlet代碼?

package com.jmh.servlet;import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.List;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import com.alibaba.fastjson.JSON; import com.jmh.biz.IModuleBiz; import com.jmh.biz.imp.ModuleBiz; import com.jmh.entity.Module;/*** 綁定左側(cè)Tree* @author 蔣明輝**/ @WebServlet("/queryModuleServlet.do") public class QueryModuleServlet extends HttpServlet{@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doGet(req, resp);}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {try {//設(shè)置編碼req.setCharacterEncoding("utf-8");resp.setContentType("text/html;charset=utf-8");//獲取對(duì)象PrintWriter out = resp.getWriter();//處理業(yè)務(wù)邏輯代碼IModuleBiz imb=new ModuleBiz();//查詢(xún)List<Module> queryPid = imb.queryPid(-1);//轉(zhuǎn)換JSon格式String jsonString = JSON.toJSONString(queryPid);out.print(jsonString);out.flush();out.close();} catch (SQLException e) {e.printStackTrace();}}}

?2.3 dao層接口代碼

package com.jmh.dao;import java.sql.SQLException; import java.util.List;import com.jmh.entity.Module;/*** 接口* @author 蔣明輝**/ public interface IModuleDao {/*** 綁定數(shù)據(jù)* @param pid 父節(jié)點(diǎn)編號(hào)* @return* @throws SQLException*/List<Module> queryPid(Integer pid) throws SQLException;}

?2.4 dao層實(shí)現(xiàn)類(lèi)代碼

package com.jmh.dao.imp;import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List;import com.jmh.dao.IModuleDao; import com.jmh.entity.Module; import com.jmh.util.DBAccess;/*** 實(shí)現(xiàn)類(lèi)* @author 蔣明輝**/ public class ModuleDao implements IModuleDao{private Connection con;private PreparedStatement ps;private ResultSet rs;private List<Module> modulels;private Module module;private String sql;private int n;/*** 綁定數(shù)據(jù)* @param pid 父節(jié)點(diǎn)編號(hào)* @return* @throws SQLException*/@Overridepublic List<Module> queryPid(Integer pid) throws SQLException {modulels=new ArrayList<>();con=DBAccess.getConnection();sql="select id,pid,text,icon,url,sort from t_module where pid=? order by sort asc";ps=con.prepareStatement(sql);ps.setInt(1, pid);rs=ps.executeQuery();while(rs.next()) {module=new Module(rs.getInt("id"), rs.getInt("pid"), rs.getString("text"), rs.getString("icon"), rs.getString("url"), rs.getInt("sort"), null);modulels.add(module);}return modulels;} }

?2.5 biz層接口代碼

package com.jmh.biz; import java.sql.SQLException; import java.util.List;import com.jmh.entity.Module; /*** 接口* @author 蔣明輝**/ public interface IModuleBiz {/*** 綁定數(shù)據(jù)* @param pid 父節(jié)點(diǎn)編號(hào)* @return* @throws SQLException*/List<Module> queryPid(Integer pid) throws SQLException; }

2.6 biz層實(shí)現(xiàn)類(lèi)代碼?

package com.jmh.biz.imp;import java.sql.SQLException; import java.util.List;import com.jmh.biz.IModuleBiz; import com.jmh.dao.IModuleDao; import com.jmh.dao.imp.ModuleDao; import com.jmh.entity.Module;public class ModuleBiz implements IModuleBiz{IModuleDao imd=new ModuleDao();@Overridepublic List<Module> queryPid(Integer pid) throws SQLException {List<Module> queryPid = imd.queryPid(pid);for (Module module : queryPid) {if(null==module.getUrl()||"".equals(module.getUrl())) {List<Module> queryPid2 = queryPid(module.getId());module.setChildren(queryPid2);}}return queryPid;} }

3. 書(shū)本展示模塊?

  • 展示全部書(shū)本?and 模糊查詢(xún)

?

  • ?增加書(shū)本

  • 編輯書(shū)本?

?

  • 刪除書(shū)本?

?

3.1 前端代碼

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <!-- 引入 --> <%@ include file="../../home/head.jsp" %> <script type="text/javascript" src="${cxt }/static/js/bookList.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <!-- 查詢(xún)組件 --> <div style="padding: 20px"> <span style="font-weight: bolder;font-size: 15px">書(shū)本名稱(chēng):</span><input id="bookName" class="easyui-textbox" data-options="iconCls:'icon-search'" style="width:300px;"> <a id="search" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查詢(xún)</a> </div> <!-- 表格數(shù)據(jù)組件 --><div class="easyui-panel" style="padding:10px" data-options="fit:true, border:false"><table class="easyui-datagrid" id="myTable" style="width: 100%;height: 80%;"></table> </div><!-- 工具欄組件 --> <div id="toolbar" style="text-align: right;"> <a id="editBook" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" /a> <a id="addBook" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" /a> <a id="removeBook" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" /a> </div> <!-- 對(duì)話(huà)框組件 --> <div id="myToolbar"></div> </body> </html>

?3.2 js代碼

$(function(){// 通過(guò) id選擇器獲取表格 $("#myTable").datagrid({// 綁定表頭columns:[[{field:'bookId',title:'書(shū)本ID',width:100,align:'center'}, {field:'bookName',title:'名稱(chēng)',width:100,align:'center'}, {field:'bookPrice',title:'價(jià)格',width:100,align:'center'},{field:'bookType',title:'類(lèi)型',width:100,align:'center'}]],// 向后臺(tái)發(fā)送 ajax請(qǐng)求url: cxt+'/queryBookServlet.do',pagination: true,// 設(shè)置是否顯示分頁(yè)標(biāo)簽singleSelect:true,// 如果為true,則只允許選擇一行(否則點(diǎn)一行選擇一行,很丑)loadMsg:"正在加載數(shù)據(jù)...",//加載數(shù)據(jù)的時(shí)候顯示提示消息toolbar: '#toolbar' }); /* 設(shè)置分頁(yè)組件的文字描述 */ var p = $('#myTable').datagrid('getPager'); $(p).pagination({ pageSize: 10,//每頁(yè)顯示的記錄條數(shù),默認(rèn)為10 pageList: [10,20,30,50,60,70,80,90,100],//可以設(shè)置可以選擇的頁(yè)大小(下拉框的內(nèi)容)beforePageText: '第',//頁(yè)數(shù)文本框前顯示的漢字 afterPageText: '頁(yè) 共 {pages} 頁(yè)', displayMsg: '當(dāng)前顯示 {from} - {to} 條記錄 共 {total} 條記錄', }); //加載數(shù)據(jù)的方法 function query(){$("#myTable").datagrid('load',{"bookName":$("#bookName").val()}) } //給查詢(xún)按鈕添加點(diǎn)擊事件 $("#search").click(function(){query(); }) //給增加按鈕添加點(diǎn)擊事件 $("#addBook").click(function(){open(); }) //給修改按鈕添加點(diǎn)擊事件 $("#editBook").click(function(){var row=$("#myTable").datagrid("getSelected");if(null==row){//為空$.messager.alert("警告","請(qǐng)選中你要修改的行");return;}open(row); }) //給刪除按鈕添加點(diǎn)擊事件 $("#removeBook").click(function(){var row=$("#myTable").datagrid("getSelected");if(null!=row){//選中的行不為空$.messager.confirm('確認(rèn)','您確認(rèn)想要?jiǎng)h除記錄嗎?',function(r){ if (r){//確認(rèn)刪除 //使用無(wú)刷新跳轉(zhuǎn)頁(yè)面$.ajax({url:cxt+'/deleteBookServlet.do',//拿數(shù)據(jù)的地址data:{"bookId":row.bookId},//很重要type:'post',//類(lèi)型dataType:'JSON',//前端希望后端所返回的數(shù)據(jù)格式success:function(data){if(data.s){//刪除成功$.messager.alert("消息",data.m);//調(diào)用刷新的方法 實(shí)現(xiàn)實(shí)時(shí)刷新query();}else{//刪除失敗$.messager.alert("警告",data.m);}}})} }); }else{//選中的行為空$.messager.alert('警告','請(qǐng)選中你要?jiǎng)h除的行!'); } }) //共用方法 function open(row){//初始title='增加書(shū)本';reqServlet='/insertBookServlet.do';if(null!=row){//row有值title='修改書(shū)本';reqServlet='/updateBookServlet.do';}$('#myToolbar').dialog({ title: title, width: 400, height: 251, closed: false, cache: false, href: cxt+'/jsp/book/editBook.jsp', //跳轉(zhuǎn)頁(yè)面表單頁(yè)面modal: true ,//添加按鈕組buttons:[{text:'提交',handler:function(){//無(wú)刷新$.ajax({url:cxt+reqServlet,//拿數(shù)據(jù)的地址data:$("#bookForm").serialize(),//很重要type:'post',//類(lèi)型dataType:'JSON',//前端希望后端所返回的數(shù)據(jù)格式success:function(data){if(data.s){//增加/修改成功$.messager.alert("消息",data.m);//調(diào)用刷新的方法 實(shí)現(xiàn)實(shí)時(shí)刷新query();//隱藏彈出框$('#myToolbar').dialog('close');}else{//增加/修改失敗$.messager.alert("警告",data.m);}}})}},{text:'關(guān)閉',handler:function(){$('#myToolbar').dialog('close'); }}],onLoad:function(){//如果row有值就綁定數(shù)據(jù)if(row){$('#bookForm').form('load',row);// 讀取表單的URL}}}) }});

3.3 點(diǎn)擊編輯or增加按鈕打開(kāi)的頁(yè)面?

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <!-- 引入 --> <%@ include file="../../home/head.jsp" %> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body><div><form id="bookForm"> <input name="bookId" type="hidden"/><!--定義一個(gè)隱藏的文本框 --><!-- 書(shū)本名稱(chēng) --><div style="margin: 15px;"> <label for="name">書(shū)名:</label> <input class="easyui-textbox" name="bookName" style="width:300px" data-options="required:true"> </div> <!-- 書(shū)本價(jià)格 --><div style="margin: 15px;"> <label for="price">價(jià)格:</label> <input class="easyui-textbox" name="bookPrice" style="width:300px" data-options="required:true"> </div><!-- 書(shū)本類(lèi)型 --><div style="margin: 15px;"> <label for="type">類(lèi)型:</label> <input class="easyui-textbox" name="bookType" style="width:300px" data-options="required:true"> </div> </form></div> </body> </html>

3.4 查詢(xún)and模糊查詢(xún)Servlet代碼?

package com.jmh.servlet;import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;import com.alibaba.fastjson.JSON; import com.jmh.biz.IBookBiz; import com.jmh.biz.imp.BookBiz; import com.jmh.entity.Book;/*** 查詢(xún)所有t_book表數(shù)據(jù)* @author 蔣明輝**/ @WebServlet("/queryBookServlet.do") public class QueryBookServlet extends HttpServlet{@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {this.doGet(req, resp);}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {try {//設(shè)置編碼req.setCharacterEncoding("utf-8");resp.setContentType("text/html;charset=utf-8");//獲取對(duì)象HttpSession session = req.getSession();PrintWriter out = resp.getWriter();//設(shè)置當(dāng)前頁(yè)碼的參數(shù)Integer pageIndex=1;//獲取前端傳來(lái)的參數(shù)String bookName = req.getParameter("bookName");//書(shū)本名稱(chēng)關(guān)鍵字String page = req.getParameter("page");//頁(yè)碼String rows = req.getParameter("rows");//頁(yè)大小//判斷如果前端傳來(lái)的頁(yè)碼有值就賦給頁(yè)碼變量if(null!=page&&!"".equals(page)) {pageIndex=Integer.parseInt(page);}//處理業(yè)務(wù)邏輯層代碼IBookBiz ibb=new BookBiz();//查詢(xún)?nèi)糠椒↙ist<Book> query = ibb.query(bookName, pageIndex, Integer.parseInt(rows));//查詢(xún)總數(shù)據(jù)量方法Integer sumCount = ibb.sumCount(bookName);//將獲取到的數(shù)據(jù)保存到map集合里面Map<Object, Object> m=new HashMap<Object, Object>();m.put("rows", query);//總數(shù)據(jù)m.put("total", sumCount);//總數(shù)據(jù)量//轉(zhuǎn)換為JOSN格式String jsonString = JSON.toJSONString(m);//輸送到前端out.print(jsonString);out.flush();out.close();} catch (NumberFormatException | SQLException e) {e.printStackTrace();}}}

?3.5 增加書(shū)本Servlet代碼

package com.jmh.servlet;import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.HashMap; import java.util.Map;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;import com.alibaba.fastjson.JSON; import com.jmh.biz.IBookBiz; import com.jmh.biz.imp.BookBiz; import com.jmh.entity.Book;/*** 增加書(shū)本* @author 蔣明輝**/ @WebServlet("/insertBookServlet.do") public class InsertBookServlet extends HttpServlet{@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doGet(req, resp);}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//設(shè)置編碼req.setCharacterEncoding("utf-8");resp.setContentType("text/html;charset=utf-8");//獲取對(duì)象HttpSession session = req.getSession();PrintWriter out=resp.getWriter();//獲取前端獲取來(lái)的參數(shù)String bookName=req.getParameter("bookName");//書(shū)本名稱(chēng)String bookPrice=req.getParameter("bookPrice");//書(shū)本價(jià)格String bookType=req.getParameter("bookType");//書(shū)本類(lèi)型//實(shí)例化對(duì)象Book book=new Book();book.setBookName(bookName);book.setBookPrice(Double.parseDouble(bookPrice));book.setBookType(bookType);//處理業(yè)務(wù)邏輯代碼IBookBiz ibb=new BookBiz();Map<Object, Object> m=new HashMap<>();try {ibb.insert(book);//沒(méi)有進(jìn)入SQLException代表增加成功m.put("s", true);m.put("m", "增加成功");} catch (SQLException e) {//代表失敗m.put("s", false);m.put("m", "增加失敗");e.printStackTrace();}String jsonString = JSON.toJSONString(m);out.print(jsonString);out.flush();out.close();}}

?3.6 編輯書(shū)本Servlet代碼

package com.jmh.servlet;import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.HashMap; import java.util.Map;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import com.alibaba.fastjson.JSON; import com.jmh.biz.IBookBiz; import com.jmh.biz.imp.BookBiz; import com.jmh.entity.Book;/*** 修改書(shū)本* @author 蔣明輝**/ @WebServlet("/updateBookServlet.do") public class UpdateBookServlet extends HttpServlet{@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doGet(req, resp);}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//設(shè)置編碼req.setCharacterEncoding("utf-8");resp.setContentType("text/html;charset=utf-8");//獲取對(duì)象PrintWriter out = resp.getWriter();//獲取前端傳送的參數(shù)String bookId=req.getParameter("bookId");String bookName=req.getParameter("bookName");String bookPrice=req.getParameter("bookPrice");String bookType=req.getParameter("bookType");/*System.out.println(bookId);System.out.println(bookName);System.out.println(bookPrice);System.out.println(bookType);*///處理業(yè)務(wù)邏輯代碼IBookBiz ibb=new BookBiz();//實(shí)例化一個(gè)書(shū)本對(duì)象Book book=new Book();book.setBookId(Integer.parseInt(bookId));book.setBookName(bookName);book.setBookPrice(Double.parseDouble(bookPrice));book.setBookType(bookType);//定義map集合Map<Object, Object> m=new HashMap<>();try {ibb.update(book);//成功m.put("s", true);m.put("m", "修改成功");} catch (SQLException e) {//失敗m.put("s", false);m.put("m", "修改失敗");e.printStackTrace();}//轉(zhuǎn)換為json格式 并輸出到前端String jsonString = JSON.toJSONString(m);out.print(jsonString);out.flush();out.close();} }

?3.7 刪除書(shū)本Servlet代碼

package com.jmh.servlet;import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.HashMap; import java.util.Map;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.support.hsf.HSFJSONUtils; import com.jmh.biz.IBookBiz; import com.jmh.biz.imp.BookBiz;/*** 刪除書(shū)本* @author 蔣明輝**/ @WebServlet("/deleteBookServlet.do") public class DeleteBookServlet extends HttpServlet{@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doGet(req, resp);}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//設(shè)置編碼req.setCharacterEncoding("utf-8");resp.setContentType("text/html;charset=utf-8");//獲取對(duì)象HttpSession session = req.getSession();PrintWriter out=resp.getWriter();//獲取前端傳來(lái)的參數(shù)String bookId = req.getParameter("bookId");System.out.println("要?jiǎng)h除的編號(hào)"+bookId);//處理業(yè)務(wù)邏輯代碼IBookBiz ibb=new BookBiz();//定義map集合Map<Object, Object> m=new HashMap<>();try {ibb.delete(bookId);m.put("s", true);m.put("m", "刪除成功!");} catch (SQLException e) {//刪除失敗m.put("s", false);m.put("m", "刪除失敗!");e.printStackTrace();}//輸送到前端String jsonString = JSON.toJSONString(m);//輸送到前端out.print(jsonString);out.flush();out.close();}}

?3.8 dao層接口代碼

package com.jmh.dao;import java.sql.SQLException; import java.util.List;import com.jmh.entity.Book;public interface IBookDao {/*** 帶有模糊查詢(xún)的分頁(yè)方法* @param bookName 模糊查詢(xún)關(guān)鍵字* @param pageIndex 當(dāng)前開(kāi)始的條數(shù)* @param pageSize 頁(yè)大小* @return 結(jié)果集對(duì)象* @throws SQLException 異常*/List<Book> query(String bookName, Integer pageIndex, Integer pageSize) throws SQLException;/*** 帶有模糊查詢(xún)的分頁(yè)方法* @param bookName 模糊查詢(xún)關(guān)鍵字* @param pageIndex 當(dāng)前開(kāi)始的條數(shù)* @param pageSize 頁(yè)大小* @return 結(jié)果集對(duì)象* @throws SQLException 異常*/Integer sumCount(String bookName) throws SQLException;/*** 增加書(shū)本的方法* @param b 書(shū)本對(duì)象* @throws SQLException 異常*/void insert(Book b) throws SQLException;/*** 根據(jù)書(shū)本編號(hào)刪除書(shū)本的方法* @param bookid 書(shū)本編號(hào)* @throws SQLException*/void delete(String bookid) throws SQLException;/*** 根據(jù)書(shū)本編號(hào)修改書(shū)本信息的方法* @param book 書(shū)本對(duì)象* @throws SQLException*/void update(Book book) throws SQLException;}

?3.9 dao層實(shí)現(xiàn)類(lèi)代碼

package com.jmh.dao.imp;import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List;import com.jmh.dao.IBookDao; import com.jmh.entity.Book; import com.jmh.entity.Module; import com.jmh.util.DBAccess;public class BookDao implements IBookDao{private Connection con;private PreparedStatement ps;private ResultSet rs;private List<Book> bookls;private Book book;private String sql;private Integer n;private Integer sumCount;//總數(shù)據(jù)量/*** 帶有模糊查詢(xún)的分頁(yè)方法* @param bookName 模糊查詢(xún)關(guān)鍵字* @param pageIndex 當(dāng)前開(kāi)始的條數(shù)* @param pageSize 頁(yè)大小* @return 結(jié)果集對(duì)象* @throws SQLException 異常*/@Overridepublic List<Book> query(String bookName,Integer pageIndex,Integer pageSize) throws SQLException {//模糊查詢(xún)關(guān)鍵字、最大頁(yè)碼、頁(yè)大小Integer begin=(pageIndex-1)*pageSize;bookls=new ArrayList<>();con=DBAccess.getConnection();//純純的分頁(yè)查詢(xún)sql="select bookId,bookName,bookPrice,bookType,bookNamePinYin from t_book where bookId limit ?,? ";if(null!=bookName&&!"".equals(bookName)) {//帶模糊查詢(xún)的分頁(yè)sql="select bookId,bookName,bookPrice,bookType,bookNamePinYin from t_book where bookName like ? or bookNamePinYin like ? and bookId limit ?,?";}ps=con.prepareStatement(sql);//判斷進(jìn)入了哪一個(gè)程序就給哪一個(gè)程序賦值if(null!=bookName&&!"".equals(bookName)) {ps.setString(1, "%"+bookName+"%");//模糊查詢(xún)關(guān)鍵字ps.setString(2, "%"+bookName+"%");//拼音模糊查詢(xún)關(guān)鍵字ps.setInt(3, begin);//每頁(yè)開(kāi)始的條數(shù)ps.setInt(4, pageSize);//頁(yè)大小}else {//分頁(yè)字段賦值ps.setInt(1, begin);//每頁(yè)開(kāi)始的條數(shù)ps.setInt(2, pageSize);//頁(yè)大小}rs=ps.executeQuery();while(rs.next()) {book=new Book(rs.getInt("bookId"), rs.getString("bookName"), rs.getDouble("bookPrice"), rs.getString("bookType"), rs.getString("bookNamePinYin"));bookls.add(book);}DBAccess.close(con, ps, rs);return bookls;}/*** 總數(shù)據(jù)量的方法* @param bookName 模糊查詢(xún)關(guān)鍵字* @return 影響條數(shù)* @throws SQLException 異常*/@Overridepublic Integer sumCount(String bookName) throws SQLException {con=DBAccess.getConnection();sql="select count(0) from t_book";//判斷如果是模糊查詢(xún)就追加sql語(yǔ)句if(null!=bookName&&!"".equals(bookName)) {sql+=" where bookName like ? or bookNamePinYin like ?";}ps=con.prepareStatement(sql);//如果是模糊查詢(xún)就給字段賦值if(null!=bookName&&!"".equals(bookName)) {ps.setString(1, "%"+bookName+"%");//模糊查詢(xún)關(guān)鍵字ps.setString(2, "%"+bookName+"%");//拼音模糊查詢(xún)關(guān)鍵字}rs=ps.executeQuery();if(rs.next()) {//給素=所有影響條數(shù)賦給定義的變量sumCount=rs.getInt(1);}DBAccess.close(con, ps, rs);return sumCount;}/*** 增加書(shū)本的方法* @param b 書(shū)本對(duì)象* @throws SQLException 異常*/@Overridepublic void insert(Book b) throws SQLException {con=DBAccess.getConnection();sql="insert into t_book(bookName,bookPrice,bookType,BookNamePinYin) values"+ "(?,?,?,?)";ps=con.prepareStatement(sql);ps.setString(1, b.getBookName());ps.setDouble(2, b.getBookPrice());ps.setString(3, b.getBookType());ps.setString(4, b.getBookNamePinYin());n=ps.executeUpdate();DBAccess.close(con, ps, rs);}/*** 根據(jù)書(shū)本編號(hào)刪除書(shū)本的方法* @param bookid 書(shū)本編號(hào)* @throws SQLException*/@Overridepublic void delete(String bookid) throws SQLException {con=DBAccess.getConnection();sql="delete from t_book where bookId=?";ps=con.prepareStatement(sql);ps.setString(1, bookid);ps.executeUpdate();DBAccess.close(con, ps, rs);}/*** 根據(jù)書(shū)本編號(hào)修改書(shū)本信息的方法* @param book 書(shū)本對(duì)象* @throws SQLException*/@Overridepublic void update(Book book) throws SQLException {con=DBAccess.getConnection();sql="update t_book set bookName=?,bookPrice=?,bookType=? where bookId=?";ps=con.prepareStatement(sql);//給占位符賦值ps.setString(1, book.getBookName());ps.setDouble(2, book.getBookPrice());ps.setString(3, book.getBookType());ps.setInt(4, book.getBookId());ps.executeUpdate();DBAccess.close(con, ps, rs);} }

?4.0 biz層接口代碼

package com.jmh.biz;import java.sql.SQLException; import java.util.List;import com.jmh.entity.Book;public interface IBookBiz {/*** 帶有模糊查詢(xún)的分頁(yè)方法* @param bookName 模糊查詢(xún)關(guān)鍵字* @param pageIndex 當(dāng)前開(kāi)始的條數(shù)* @param pageSize 頁(yè)大小* @return 結(jié)果集對(duì)象* @throws SQLException 異常*/List<Book> query(String bookName, Integer pageIndex, Integer pageSize) throws SQLException;/*** 帶有模糊查詢(xún)的分頁(yè)方法* @param bookName 模糊查詢(xún)關(guān)鍵字* @param pageIndex 當(dāng)前開(kāi)始的條數(shù)* @param pageSize 頁(yè)大小* @return 結(jié)果集對(duì)象* @throws SQLException 異常*/Integer sumCount(String bookName) throws SQLException;/*** 增加書(shū)本的方法* @param b 書(shū)本對(duì)象* @throws SQLException 異常*/void insert(Book b) throws SQLException;/*** 根據(jù)書(shū)本編號(hào)刪除書(shū)本的方法* @param bookid 書(shū)本編號(hào)* @throws SQLException*/void delete(String bookid) throws SQLException;/*** 根據(jù)書(shū)本編號(hào)修改書(shū)本信息的方法* @param book 書(shū)本對(duì)象* @throws SQLException*/void update(Book book) throws SQLException;}

?4.1 biz層實(shí)現(xiàn)類(lèi)代碼

package com.jmh.biz.imp;import java.sql.SQLException; import java.util.List;import com.jmh.biz.IBookBiz; import com.jmh.dao.IBookDao; import com.jmh.dao.imp.BookDao; import com.jmh.entity.Book;public class BookBiz implements IBookBiz{IBookDao ibd=new BookDao();@Overridepublic List<Book> query(String bookName, Integer pageIndex, Integer pageSize) throws SQLException {// TODO Auto-generated method stubreturn ibd.query(bookName, pageIndex, pageSize);}@Overridepublic Integer sumCount(String bookName) throws SQLException {// TODO Auto-generated method stubreturn ibd.sumCount(bookName);}@Overridepublic void insert(Book b) throws SQLException {ibd.insert(b);}@Overridepublic void delete(String bookid) throws SQLException {ibd.delete(bookid);}@Overridepublic void update(Book book) throws SQLException {ibd.update(book);}}

?


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

?

?

?

?

總結(jié)

以上是生活随笔為你收集整理的EasyUI后台管理系统的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。