EasyUI DataGrid数据显示

EasyUI DataGrid数据显示,第1张

DataGrid(数据表格)

DataGrid以表格形式展示数据,并提供了丰富的选择、排序、分组和编辑数据的功能支持。DataGrid的设计用于缩短开发时间,并且使开发人员不需要具备特定的知识。它是轻量级的且功能丰富。单元格合并、多列标题、冻结列和页脚只是其中的一小部分功能。

实现的页面效果图:

数据分页显示:

底下的分页下拉框可以显示指定的条数 及显示第几页

 根据名字进行模糊查询:

   数据库的建立
insert into bs_permission values(seq_permission.nextval,3,'商品首页','list.jsp');
select * from bs_permission;
commit


CREATE TABLE BS_BOOK
(
    ID    NUMBER PRIMARY KEY,
    NAME  VARCHAR(50) NOT NULL,
    PRICE NUMBER      NOT NULL
);

INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (20, '生活会给你答案', 62.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (21, '凡人修仙传', 90.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (22, '吞噬星空', 52.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (26, '重生之贼行天下', 84.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (27, '择天记', 6.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (28, '我的美女总裁老婆', 77.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (29, '爵迹·风津道', 70.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (30, '神墓', 88.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (31, '寻花问柳', 89.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (32, '仙逆', 86.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (33, '天珠变', 49.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (34, '重生之官道', 45.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (35, '春莺啭', 44.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (36, '永生', 26.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (37, '覆雨翻云', 59.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (38, '完美世界', 5.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (39, '活色生香', 60.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (40, '武动乾坤', 0.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (41, '眸倾天下', 63.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (42, '临界·爵迹2', 34.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (43, '恐怖高校', 37.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (44, '大罗金仙异界销魂', 92.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (45, '我把爱情煲成汤', 24.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (46, '罂粟的情人', 36.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (47, '魔兽剑圣异界纵横', 63.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (48, '香初上舞', 78.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (49, '莽荒纪', 5.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (50, '重生1998', 69.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (51, '晚明', 42.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (52, '空战极限', 56.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (53, '风临异世', 83.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (54, '傲世九重天', 20.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (55, '造化之门', 6.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (56, '武神', 26.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (57, '婚宠之枭妻霸爱', 78.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (58, '斗破苍穹', 96.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (59, '主神崛起', 11.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (60, '异世邪君', 71.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (61, '富贵锦绣', 61.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (62, '绝品医仙', 68.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (63, '杀手之王', 27.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (64, '极乐篮球风暴', 42.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (65, '极度修真', 58.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (66, '慧眼问道', 42.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (67, '混沌劫', 71.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (68, '混沌修真诀', 47.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (69, '华夏立国传', 15.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (70, '鸿蒙玄天曲', 9.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (71, '洪荒之金口玉言', 80.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (72, '横行在异世', 19.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (73, '鬼王的毒妃', 15.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (74, '和亲娇妃', 46.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (75, '宠物小精灵之小天', 41.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (76, '总裁的俏保镖', 54.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (77, '毒仙', 78.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (78, '钻石女人极品男', 96.00);
INSERT INTO BS_BOOK (ID, NAME, PRICE)
VALUES (79, '亡命奴妃', 11.00);

select*from bs_book
commit
 list.jsp(商品首页)
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>




Insert title here







	
		
		
	
	
BookDao.java 
package com.zking.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.zking.pojo.Book;
import com.zking.pojo.Permission;
import com.zking.util.DBHelper;

public class BookDao {
 
	    private Connection con;
	    private PreparedStatement ps;
	    private ResultSet rs;
	 
	    /**
	     * 分页查询
	     * @param page 页数
	     * @param rows 行数
	     * @param name 名称
	     * @return
	     */
	    public List list(int page,int rows,String name) {
	        List list = new ArrayList();
	        int begin=(page-1)*rows+1;
	        int end=page*rows;
	        try {
	            con = DBHelper.getCon();
	            ps = con.prepareStatement("select * from (select a.*,rownum myr from bs_book a where name like ?)b where myr between ? and ? ");
	            ps.setString(1, "%"+name+"%");
	            ps.setInt(2, begin);
	            ps.setInt(3, end);
	            rs = ps.executeQuery();
	            while (rs.next()) {
	               Book b=new Book(rs.getInt(1),rs.getString(2),rs.getDouble(3));
	               list.add(b);
	            }
	        } catch (Exception e) {
	            e.printStackTrace();
	        } finally {
	            DBHelper.close(con, ps, rs);
	        }
	        return list;
	    }
	    
	    /**
	     * 根据名字模糊查询
	     * @param name
	     * @return
	     */
	    public Integer total(String name) {
	    	try {
				con=DBHelper.getCon();
				ps=con.prepareStatement("select count(1) from bs_book where name like ?");
			    ps.setString(1, "%"+name+"%");
			    rs=ps.executeQuery();
			    while(rs.next()) {
			    	return rs.getInt(1);
			    }
	    	} catch (Exception e) {
				e.printStackTrace();
			}finally {
				DBHelper.close(con, ps, rs);
			}
	    	return 0;
	    }
}
 PageBean.java(负责分页与数据传递)
package com.zking.pojo;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
//负责分页与数据传递
public class PageBean {

	private Integer total;
	private List rows;
	private Integer page=1;
	private Integer row=5;
	public Integer getTotal() {
		return total;
	}
	public void setTotal(Integer total) {
		this.total = total;
	}
	public List getRows() {
		return rows;
	}
	public void setRows(List rows) {
		this.rows = rows;
	}
	public Integer getPage() {
		return page;
	}
	public void setPage(Integer page) {
		this.page = page;
	}
	public Integer getRow() {
		return row;
	}
	public void setRow(Integer row) {
		this.row = row;
	}
	public PageBean(Integer total, List rows, Integer page, Integer row) {
		super();
		this.total = total;
		this.rows = rows;
		this.page = page;
		this.row = row;
	}
	
	public PageBean() {
		// TODO Auto-generated constructor stub
	}
	@Override
	public String toString() {
		return "PageBean [total=" + total + ", rows=" + rows + ", page=" + page + ", row=" + row + "]";
	}
	//拿到请求中的分页数据
	public void setReq(HttpServletRequest req) {
		String p = req.getParameter("page");
        if(p!=null) {
        	page=Integer.parseInt(p);
        }
        String r = req.getParameter("rows");
        if(r!=null) {
        	row=Integer.parseInt(r);
        }
	}
	
}
Book.java(书籍实体类)
package com.zking.pojo;

public class Book {

	private Integer id;
	private String name;
	private Double price;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	public Book(Integer id, String name, Double price) {
		super();
		this.id = id;
		this.name = name;
		this.price = price;
	}
	
	public Book() {
		// TODO Auto-generated constructor stub
	}
	@Override
	public String toString() {
		return "Book [id=" + id + ", name=" + name + ", price=" + price + "]";
	}
	
	
}
BookServlet.java
package com.zking.servlet;

import java.io.IOException;
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.fasterxml.jackson.databind.ObjectMapper;
import com.zking.dao.BookDao;
import com.zking.dao.PermissionDao;
import com.zking.pojo.Book;
import com.zking.pojo.PageBean;
@WebServlet("/book.do")
public class BookServlet extends HttpServlet{

	private BookDao bookDao=new BookDao();
    private ObjectMapper mapper = new ObjectMapper();
 
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	doPost(req, resp);
    }
 
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       
        String name="";
        
        String n = req.getParameter("name");
        if(n!=null) {
        	name=n;
        }
        PageBean pb=new PageBean();
        pb.setReq(req);
        resp.setCharacterEncoding("gb2312");
        pb.setTotal(bookDao.total(name));
        pb.setRows(bookDao.list(pb.getPage(), pb.getRow(), name));
        mapper.writeValue(resp.getOutputStream(),pb);
    }
}

今天的分享就要这结束啦!!✌

以上就是关于EasyUI DataGrid数据显示的一些内容!!📖

期待下次再见!!😊

 

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

原文地址: http://outofmemory.cn/langs/919944.html

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

发表评论

登录后才能评论

评论列表(0条)

保存