easyui 数据表实现模糊查询新增修改删除

easyui 数据表实现模糊查询新增修改删除,第1张

准备数据表 模拟 
create table tb_book
(
       bid number primary key,--书籍id
       bname varchar2(100),--书籍名称
       bprice number(5,2),--书籍价格
       btype varchar2(100)--书籍类型
       
)
select * from tb_book;

1.1 DataGrid基本属性

   1.1.1 基本属性
      url : '',         // 初始化请求路径
      fitcolumns : false,     // 列宽自适应
      singleSelect : true,     // 是否选中单行
      checkOnSelect : true,     // 点击行选中时该checkbox选中或取消选中
      rownumbers:true,            // 行号
      fit : true,         // 高宽自适应
      border : false,             // 是否显示边框
      title : '书本列表',     // datagrid标题
      striped : true,             // 显示斑马线效果

 表格布局

 需要引入共享架包页面

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>




















<%
	String xPath = request.getServletContext().getContextPath();
	session.setAttribute("xPath", xPath);
%>
对话窗口 引入添加修改界面 
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

	
主界面数据表格 
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here
<%@include file="static/common/eayUI_llink.jsp" %>




   
   

搜索
   
   




   
加载数据servlet界面
package com.zking.easyui.book.servlet;

import java.io.IOException;
import java.io.PrintWriter;
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 com.fasterxml.jackson.databind.ObjectMapper;
import com.zking.easyui.book.biz.IBookBiz;
import com.zking.easyui.book.biz.impl.BookBizImpl;
import com.zking.easyui.book.entity.Book;

/**
 * 显示所有图书的控制器servlet
 */
@WebServlet("/BookListServlet")
public class BookListServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//编码
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json;charset=utf-8");
		
		//获取请求参数(pageIndex,searchName)
		int pageIndex = 1;
		
		String pIndex = request.getParameter("page");//page值是已经固定好
		if(pIndex!=null) {
			pageIndex = Integer.valueOf(pIndex);
		}
		
		int pageSize = 10;
		String pSize = request.getParameter("rows");
		if(pSize!=null) {
			pageSize = Integer.valueOf(pSize);
		}
		
		
		//获取searchName
		String searchName = request.getParameter("searchName");
		if(searchName == null) {
			searchName = "";
		}
		System.out.println("searchName = "+searchName);
		
		
		//调用biz
		IBookBiz ibb = new BookBizImpl();
		//获取总记录数
		Integer tableCount = ibb.getTableCount(searchName);
		// 总数据
		List booksAll = ibb.getBooksAll(pageIndex, pageSize, searchName);
		//实例化Map集合
		Map maps = new HashMap();
		maps.put("total", tableCount);
		maps.put("rows", booksAll);
		
		//创建JSON工具
		ObjectMapper mapper = new ObjectMapper();
		String writeValueAsString = mapper.writeValueAsString(maps);
		
//		获取out
		PrintWriter out = response.getWriter();
		out.write(writeValueAsString);
		out.flush();
		out.close();

	}

}
删除servlet界面
package com.zking.easyui.book.servlet;

import java.io.IOException;
import java.io.PrintWriter;
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 com.fasterxml.jackson.databind.ObjectMapper;
import com.zking.easyui.book.biz.IBookBiz;
import com.zking.easyui.book.biz.impl.BookBizImpl;
import com.zking.easyui.book.entity.Book;

/**
 * 删除图书的servlet控制器
 */
@WebServlet("/DelBookServlet")
public class DelBookServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//编码
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json;charset=utf-8");
		
		//获取请求参数(pageIndex,searchName)
		Integer bid = request.getParameter("bid")!=null?Integer.valueOf(request.getParameter("bid")):0;
		
		//封装
		
		IBookBiz ibb = new BookBizImpl();
		Map maps = new HashMap<>();
		
		try {
			ibb.delBook(bid);
			maps.put("message", true);
		} catch (Exception e) {
			maps.put("message", false);
		}
		
		//获取out
		PrintWriter out = response.getWriter();
		
		ObjectMapper mapper = new ObjectMapper();
		
		String writeValueAsString = mapper.writeValueAsString(maps);
		
		out.write(writeValueAsString);
		out.flush();
		out.close();

	
	}

}
修改新增和界面
package com.zking.book.servlet;

import java.io.IOException;
import java.io.PrintWriter;
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 com.fasterxml.jackson.databind.ObjectMapper;
import com.zking.book.biz.BookBiz;
import com.zking.book.biz.impl.BookBizImpl;
import com.zking.book.entity.Book;

/**
 * Servlet implementation class BookListServlet
 */
@WebServlet("/EdetBookServlet.do")
public class EdetBookServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json;charset=utf-8");
		
	
		Map map=new HashMap<>();
		Integer bid=0;
		String parameter = request.getParameter("bid");
		if(parameter!=null&¶meter!="") {
			bid=Integer.valueOf(parameter);
		}
		
				//request.getParameter("bid")==null?0:Integer.valueOf(request.getParameter("bid"));
		String bname = request.getParameter("bname");
		Float bprice = request.getParameter("bprice")!=null?Float.valueOf(request.getParameter("bprice")):0;
		String btype = request.getParameter("btype");
		try {
			
			if(bid==0) {
				
				new BookBizImpl().addBook(new Book(bname, bprice, btype));
			}else {
				new BookBizImpl().updBook(new Book(bid, bname, bprice, btype));
			}
			
			
			map.put("Zt", true);
		} catch (Exception e) {
			
			map.put("Zt", false);
		}
		
		ObjectMapper mapper = new ObjectMapper(); 
		
		String writeValueAsString = mapper.writeValueAsString(map);
		//获取out 输出对象
		PrintWriter out = response.getWriter();
		out.write(writeValueAsString);
		out.flush();
		out.close();
	}

}
演示效果

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/944341.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-18
下一篇 2022-05-18

发表评论

登录后才能评论

评论列表(0条)

保存