Easyui部分展示

数据库脚本

创建的book表

DROP TABLE IF EXISTS `book`;
CREATE TABLE `book`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `bookname` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `price` float NOT NULL,
  `booktype` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 46 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '书本信息表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of book
-- ----------------------------
INSERT INTO `book` VALUES (3, '三国演义', 121.12, '1');
INSERT INTO `book` VALUES (6, '倚天屠龙记', 150.16, '2');
INSERT INTO `book` VALUES (10, '聊斋志异', 100.12, '2');
INSERT INTO `book` VALUES (14, '万域之王', 56.55, '3');
INSERT INTO `book` VALUES (19, '凡人修仙传', 200, '1');
INSERT INTO `book` VALUES (20, '倚天屠龙记', 150.16, '2');
INSERT INTO `book` VALUES (21, '斗破苍穹', 115.07, '3');
INSERT INTO `book` VALUES (22, '超级兵王', 145, '3');
INSERT INTO `book` VALUES (23, '武极天下', 45.55, '4');
INSERT INTO `book` VALUES (24, '聊斋志异', 100.12, '4');
INSERT INTO `book` VALUES (25, '永生', 110.11, '2');
INSERT INTO `book` VALUES (26, '武动乾坤', 90.89, '1');
INSERT INTO `book` VALUES (27, '完美世界', 100, '4');
INSERT INTO `book` VALUES (28, '万域之王', 56.5, '5');
INSERT INTO `book` VALUES (32, 'Java', 1000, '3');
INSERT INTO `book` VALUES (33, '娃哈哈', 100, '2');
INSERT INTO `book` VALUES (35, '呼啸山庄', 123, '4');
INSERT INTO `book` VALUES (36, '平凡的世界', 123, '3');
INSERT INTO `book` VALUES (38, '大红底', 12, '5');
INSERT INTO `book` VALUES (39, '坻崿', 23, '2');
INSERT INTO `book` VALUES (40, '测试费', 23, '3');
INSERT INTO `book` VALUES (41, '成都市', 123, '5');
INSERT INTO `book` VALUES (42, '平凡的世界', 68, '2');
INSERT INTO `book` VALUES (44, '论语', 100, '1');
INSERT INTO `book` VALUES (45, '师傅', 100, '2');

 创建的t_book_type

DROP TABLE IF EXISTS `t_book_type`;
CREATE TABLE `t_book_type`  (
  `type_id` int(11) NOT NULL,
  `type_deac` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  PRIMARY KEY (`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of t_book_type
-- ----------------------------
INSERT INTO `t_book_type` VALUES (1, '都市');
INSERT INTO `t_book_type` VALUES (2, '玄幻');
INSERT INTO `t_book_type` VALUES (3, '爱情');
INSERT INTO `t_book_type` VALUES (4, '武侠');
INSERT INTO `t_book_type` VALUES (5, '科幻');

创建的t_module

DROP TABLE IF EXISTS `t_module`;
CREATE TABLE `t_module`  (
  `id` int(11) DEFAULT NULL,
  `pid` int(11) DEFAULT NULL,
  `text` varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `icon` varchar(90) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `url` varchar(180) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `sort` int(11) DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of t_module
-- ----------------------------
INSERT INTO `t_module` VALUES (20, -1, '订单管理', NULL, '', 2);
INSERT INTO `t_module` VALUES (2001, 20, '订单管理', NULL, '/orderList.jsp', 6);
INSERT INTO `t_module` VALUES (2002, 20, '订单统计', NULL, '/orderStatistics.jsp', 7);
INSERT INTO `t_module` VALUES (21, -1, '系统管理', NULL, '', 3);
INSERT INTO `t_module` VALUES (2101, 21, '用户管理', NULL, 'jsp/system/userManage.jsp', 8);
INSERT INTO `t_module` VALUES (2102, 21, '权限管理', NULL, 'jsp/system/authManage.jsp', 10);
INSERT INTO `t_module` VALUES (2103, 21, '字典管理', NULL, '/dictList.jsp', 11);
INSERT INTO `t_module` VALUES (22, -1, '书本管理', NULL, '', 1);
INSERT INTO `t_module` VALUES (2201, 22, '新增书本', NULL, 'jsp/book/addBook.jsp', 4);
INSERT INTO `t_module` VALUES (2202, 22, '书本管理', NULL, 'jsp/book/bookList.jsp', 5);

 src和actin同级目录

 config.xml

<config>
	<action path="/moduleAction" type="com.zking.action.ModuleAction">
	
	</action>
	
	<action path="/bookAction" type="com.zking.action.BookAction">
	
	</action>
</config>

 jdbc.properties

driver.name = com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/t264?useUnicode=true&characterEncoding=utf-8&useSSL=false
db.user=root
db.password=123

com.zking.module

 Book实体类

package com.zking.module;

import java.math.BigDecimal;

import org.lisen.mvc.util.AutoIncrement;
import org.lisen.mvc.util.Column;
import org.lisen.mvc.util.InsertIgnore;
import org.lisen.mvc.util.Key;
import org.lisen.mvc.util.Table;

@Table("book")//是数据库的哪个表
public class Book {
	@Key
	@AutoIncrement
	private  Integer  id;
	
	@Column("bookname")
	private String bookname;
	
	@Column("booktype")
	private String booktype;
	
	@Column("price")
	private  BigDecimal  price;
	
	@Column("type_deac")
	@InsertIgnore
	private  String  typeDesc;
	

	public String getTypeDesc() {
		return typeDesc;
	}

	public void setTypeDesc(String typeDesc) {
		this.typeDesc = typeDesc;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getBookname() {
		return bookname;
	}

	public void setBookname(String bookname) {
		this.bookname = bookname;
	}

	public String getBooktype() {
		return booktype;
	}

	public void setBooktype(String booktype) {
		this.booktype = booktype;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((bookname == null) ? 0 : bookname.hashCode());
		result = prime * result + ((booktype == null) ? 0 : booktype.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((price == null) ? 0 : price.hashCode());
		result = prime * result + ((typeDesc == null) ? 0 : typeDesc.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Book other = (Book) obj;
		if (bookname == null) {
			if (other.bookname != null)
				return false;
		} else if (!bookname.equals(other.bookname))
			return false;
		if (booktype == null) {
			if (other.booktype != null)
				return false;
		} else if (!booktype.equals(other.booktype))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (price == null) {
			if (other.price != null)
				return false;
		} else if (!price.equals(other.price))
			return false;
		if (typeDesc == null) {
			if (other.typeDesc != null)
				return false;
		} else if (!typeDesc.equals(other.typeDesc))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Book [id=" + id + ", bookname=" + bookname + ", booktype=" + booktype + ", type_desc=" + typeDesc
				+ ", price=" + price + "]";
	}

	

	

	
	

}

 Module实体类

package com.zking.module;

public class Module {
	private Integer  id;
	
	private Integer pid;
	
	private  String text;
	
	private  String icon;
	
	private String url;
	
	private Integer sort;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getPid() {
		return pid;
	}

	public void setPid(Integer pid) {
		this.pid = pid;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	@Override
	public String toString() {
		return "Module [id=" + id + ", pid=" + pid + ", text=" + text + ", icon=" + icon + ", url=" + url + ", sort="
				+ sort + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((icon == null) ? 0 : icon.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((pid == null) ? 0 : pid.hashCode());
		result = prime * result + ((sort == null) ? 0 : sort.hashCode());
		result = prime * result + ((text == null) ? 0 : text.hashCode());
		result = prime * result + ((url == null) ? 0 : url.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Module other = (Module) obj;
		if (icon == null) {
			if (other.icon != null)
				return false;
		} else if (!icon.equals(other.icon))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (pid == null) {
			if (other.pid != null)
				return false;
		} else if (!pid.equals(other.pid))
			return false;
		if (sort == null) {
			if (other.sort != null)
				return false;
		} else if (!sort.equals(other.sort))
			return false;
		if (text == null) {
			if (other.text != null)
				return false;
		} else if (!text.equals(other.text))
			return false;
		if (url == null) {
			if (other.url != null)
				return false;
		} else if (!url.equals(other.url))
			return false;
		return true;
	}
	
	

}

 BookTyep实体类

package com.zking.module;

import org.lisen.mvc.util.Column;
import org.lisen.mvc.util.Key;
import org.lisen.mvc.util.Table;

@Table("t_book_type")
public class BookType {
	@Key
	@Column("type_id")
	private Integer  typeId;
	@Column("type_deac")
	private String  typeDesc;
	public Integer getTypeId() {
		return typeId;
	}
	public void setTypeId(Integer typeId) {
		this.typeId = typeId;
	}
	public String getTypeDesc() {
		return typeDesc;
	}
	public void setTypeDesc(String typeDesc) {
		this.typeDesc = typeDesc;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((typeDesc == null) ? 0 : typeDesc.hashCode());
		result = prime * result + ((typeId == null) ? 0 : typeId.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BookType other = (BookType) obj;
		if (typeDesc == null) {
			if (other.typeDesc != null)
				return false;
		} else if (!typeDesc.equals(other.typeDesc))
			return false;
		if (typeId == null) {
			if (other.typeId != null)
				return false;
		} else if (!typeId.equals(other.typeId))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "BookType [typeId=" + typeId + ", typeDesc=" + typeDesc + "]";
	}
	

}

 com.zking.dao

BookDao 

package com.zking.dao;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.lisen.mvc.util.DbTemplate;
import org.lisen.mvc.util.PageBean;

import com.mysql.jdbc.StringUtils;
import com.zking.module.Book;
import com.zking.module.BookType;

public class BookDao {
	
	public List<Book> listBooks(String  bookName,PageBean  pageBean){
		String sql="select t1.bookname,t1.id,t1.booktype,t2.type_deac,t1.price from book t1 inner  join  t_book_type t2  on t1.booktype=t2.type_id where  1=1  ";
		List<Object> param=new  ArrayList<>();
		if(bookName != null && !"".equals(bookName)) {
			sql+="  and  bookname  like ?  ";
			param.add(bookName+"%");
		}
		
		List<Book> books = DbTemplate.query(sql,param.toArray(),pageBean, Book.class);
		
		return  books;
	}
	//增加
	public int addBook(Book  book) {
		return  DbTemplate.save(book);
	}
	//修改
	public int  updateBook(Book  book) {
		return DbTemplate.update(book);
	}
	
	public int  delBook(Book  book) {
		String sql="delete  from  book  where  id=?";
		return DbTemplate.update(sql,new  Object[] {book.getId()});
	}
	
	
	public   List<BookType>  getBookTypeAll(){
		String  sql="select *  from  t_book_type";
		return  DbTemplate.query(sql, BookType.class);
	}
	@Test
	public  void  testBookType() {
		BookDao  dao=new BookDao();
		List<BookType> bookTypeAll = dao.getBookTypeAll();
		bookTypeAll.forEach(t->System.out.println(t));
	}
	
	@Test
	public  void  test() {
		
		BookDao  dao=new BookDao();
		List<Book> listBooks = dao.listBooks(null, new  PageBean());
		listBooks.forEach(t->System.out.println(t));
	}
	
	@Test
	public void  testAddBook() {
		Book  book=new  Book();
		book.setBookname("师傅");
		book.setBooktype("速度");
		book.setPrice(BigDecimal.valueOf(100));
		BookDao  bookDao=new  BookDao();
		bookDao.addBook(book);
	}
	
	@Test
	public  void  testUpdate() {
		Book  book=new  Book();
		book.setId(19);
		book.setBookname("士大夫");
		book.setBooktype("的方式");
		book.setPrice(BigDecimal.valueOf(231));
		BookDao  bookDao=new  BookDao();
		bookDao.updateBook(book);
	}

}

ModuleDao

package com.zking.dao;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.lisen.mvc.util.DbTemplate;
import org.lisen.mvc.util.PageBean;

import com.mysql.jdbc.StringUtils;
import com.zking.module.Book;
import com.zking.module.BookType;

public class BookDao {
	
	public List<Book> listBooks(String  bookName,PageBean  pageBean){
		String sql="select t1.bookname,t1.id,t1.booktype,t2.type_deac,t1.price from book t1 inner  join  t_book_type t2  on t1.booktype=t2.type_id where  1=1  ";
		List<Object> param=new  ArrayList<>();
		if(bookName != null && !"".equals(bookName)) {
			sql+="  and  bookname  like ?  ";
			param.add(bookName+"%");
		}
		
		List<Book> books = DbTemplate.query(sql,param.toArray(),pageBean, Book.class);
		
		return  books;
	}
	//增加
	public int addBook(Book  book) {
		return  DbTemplate.save(book);
	}
	//修改
	public int  updateBook(Book  book) {
		return DbTemplate.update(book);
	}
	
	public int  delBook(Book  book) {
		String sql="delete  from  book  where  id=?";
		return DbTemplate.update(sql,new  Object[] {book.getId()});
	}
	
	
	public   List<BookType>  getBookTypeAll(){
		String  sql="select *  from  t_book_type";
		return  DbTemplate.query(sql, BookType.class);
	}
	@Test
	public  void  testBookType() {
		BookDao  dao=new BookDao();
		List<BookType> bookTypeAll = dao.getBookTypeAll();
		bookTypeAll.forEach(t->System.out.println(t));
	}
	
	@Test
	public  void  test() {
		
		BookDao  dao=new BookDao();
		List<Book> listBooks = dao.listBooks(null, new  PageBean());
		listBooks.forEach(t->System.out.println(t));
	}
	
	@Test
	public void  testAddBook() {
		Book  book=new  Book();
		book.setBookname("师傅");
		book.setBooktype("速度");
		book.setPrice(BigDecimal.valueOf(100));
		BookDao  bookDao=new  BookDao();
		bookDao.addBook(book);
	}
	
	@Test
	public  void  testUpdate() {
		Book  book=new  Book();
		book.setId(19);
		book.setBookname("士大夫");
		book.setBooktype("的方式");
		book.setPrice(BigDecimal.valueOf(231));
		BookDao  bookDao=new  BookDao();
		bookDao.updateBook(book);
	}

}

com.zking.action 

BookAction 

package com.zking.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lisen.mvc.framework.AbstractDispatchAction;
import org.lisen.mvc.framework.ModelDrive;
import org.lisen.mvc.util.PageBean;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zking.dao.BookDao;
import com.zking.module.Book;
import com.zking.module.BookType;

public class BookAction extends AbstractDispatchAction implements ModelDrive{

	private  Book  book=new  Book();
	
	private  BookDao  dao=new  BookDao();
	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		return book;
	}
	
	public  void   getBooks(HttpServletRequest  req,HttpServletResponse  resp) throws Exception, JsonMappingException, IOException {
		PageBean  pageBean=new  PageBean();
		pageBean.setRequest(req);
		
		Map<String,Object>  data=new  HashMap<String, Object>();
		
		List<Book> listBooks = dao.listBooks(book.getBookname(), pageBean);
		
		data.put("total", pageBean.getTotal());
		data.put("rows", listBooks);
		
	    ObjectMapper mapper = new	ObjectMapper();  
	    
	    mapper.writeValue(resp.getOutputStream(), data);
	    
	}
	
	
	public  void   getBookTyepAll(HttpServletRequest  req,HttpServletResponse  resp) throws Exception, JsonMappingException, IOException {
		List<BookType> all = dao.getBookTypeAll();
		
	    ObjectMapper mapper = new	ObjectMapper();  
	    
	    mapper.writeValue(resp.getOutputStream(), all);
	    
	}
	
	
	public  void   addBook(HttpServletRequest  req,HttpServletResponse  resp) throws Exception, JsonMappingException, IOException {
		
		ObjectMapper mapper = new	ObjectMapper(); 
		Map<String,Object> data=new HashMap<>();
		//记得打印异常,不要把异常吞了
		try {
			dao.addBook(book);
			data.put("success", true);//成功
			data.put("msg", "操作成功");//给的提示
		}catch (Exception e) {//出现异常代表没有成功
			//throw  new  RuntimeErrorException(null);抛出异常
			e.printStackTrace();//打印异常
			data.put("success", false);//失败
			data.put("msg","操作失败");
		}
	    
	    mapper.writeValue(resp.getOutputStream(), data);
	    
	}
	
  public  void   updateBook(HttpServletRequest  req,HttpServletResponse  resp) throws Exception, JsonMappingException, IOException {
		
		ObjectMapper mapper = new	ObjectMapper(); 
		Map<String,Object> data=new HashMap<>();
		//记得打印异常,不要把异常吞了
		try {
			//判断是否有id,如果有代表是修改
			//if(book.getId()== null) {
			//	dao.addBook(book);
			//}else {
			//	dao.updBook(book);
			//}
			dao.updateBook(book);
			data.put("success", true);//成功
			data.put("msg", "操作成功");//给的提示
		}catch (Exception e) {//出现异常代表没有成功
			//throw  new  RuntimeErrorException(null);抛出异常
			e.printStackTrace();//打印异常
			data.put("success", false);//失败
			data.put("msg","操作失败");
		}
	    
	    mapper.writeValue(resp.getOutputStream(), data);
	    
	}
  
  
  public  void   delBook(HttpServletRequest  req,HttpServletResponse  resp) throws Exception, JsonMappingException, IOException {
		
		ObjectMapper mapper = new	ObjectMapper(); 
		Map<String,Object> data=new HashMap<>();
		//记得打印异常,不要把异常吞了
		try {
			dao.delBook(book);
			data.put("success", true);//成功
			data.put("msg", "操作成功");//给的提示
		}catch (Exception e) {//出现异常代表没有成功
			//throw  new  RuntimeErrorException(null);抛出异常
			e.printStackTrace();//打印异常
			data.put("success", false);//失败
			data.put("msg","操作失败");
		}
	    
	    mapper.writeValue(resp.getOutputStream(), data);
	    
	}
	
	
	

}

 Module

package com.zking.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lisen.mvc.framework.AbstractDispatchAction;
import org.lisen.mvc.framework.ModelDrive;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zking.dao.ModuleDao;
import com.zking.module.Module;

public class ModuleAction  extends AbstractDispatchAction  implements  ModelDrive{

	private Module  m=new  Module();
	
	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		return m;
	}
	
	private  ModuleDao dao=new  ModuleDao();
	
	
	public void getModules(HttpServletRequest  req,HttpServletResponse  resp) throws Exception, JsonMappingException, IOException {
		
		List<Module> list = dao.getModules(m.getPid());
        list.forEach(t->System.out.println(t));
		ObjectMapper  mapper=new  ObjectMapper();
		//获取到流
		mapper.writeValue(resp.getOutputStream(), list);
		
		
	}


	

	
}

 jsp页面部分

webapp顶级目录

同级目录为

common

js

jsp

META-INF

WEB-INF

index.jsp

 common


<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
   
   <%
   request.setAttribute("ctx", request.getContextPath());
   %>
   

 <!--写的一个公告页面用来引用  -->
 
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="${ctx}/js/jquery-easyui-1.5.5.2/jquery.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery-easyui-1.5.5.2/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery-easyui-1.5.5.2/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" type="text/css" href="${ctx}/js/jquery-easyui-1.5.5.2/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="${ctx}/js/jquery-easyui-1.5.5.2/themes/icon.css"/>

<!--不要页面缓存,方便改样式-->
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">

 js

jquery-easyui-1.5.5.2(easyui的帮助包)

jsp

   book

bookList.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>书本管理</title>
<%@ include file="../../common/head.jsp"%>
</head>
<body>

<div  style="margub-bottim:10px;"> 
  <input id="bookname" class="easyui-textbox"  style="width:200px"> 
  <a id="bookbtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>  
</div>
<table id="booktable" class="easyui-datagrid" data-options="fitColumns:true,pagination:true,title:'书本信息列表',singleSelect:true,toolbar:'#tb',singleSelect:true">   
    <thead>   
        <tr>   
            <th data-options="field:'id'" styple='width: 80px;'>编码</th>   
            <th data-options="field:'bookname'"styple='width: 150px;'>名称</th>   
            <th data-options="field:'price'" styple='width: 80px;'>价格</th>   
            <th data-options="field:'typeDesc'"styple='width: 80px;'>类型</th>   
        </tr>   
    </thead>   
</table>  

<div id="tb" style="text-align:right;">
<a href="#" id="bookadd" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true"></a>
<a href="#" id="bookupd" class="easyui-linkbutton" data-options="iconCls:'icon-cut',plain:true"></a>
<a href="#" id="bookdel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true"></a>
</div>
<div id="dd"></div>

<script type="text/javascript">
$(function(){
	
	$("#booktable").datagrid({
		url:'${ctx}/bookAction.action?methodName=getBooks'
	});
	
	
	$("#bookbtn").click(function(){
		 qryBook();
	})
	
	function  qryBook(){
		$("#booktable").datagrid("load",{
			bookname:$("#bookname").val()
		});
	}
	
	$("#bookadd").click(function(){
		open();
	});
	
	$("#bookupd").click(function(){
		debugger;
		let  s=$("#booktable").datagrid('getSelected');
		if(!s){
			$.messager.alert('消息','请选择要修改的记录','info');
			return  ;
		}
		open(s);
	});
	

	
	function  open(s){
		let  title="增加书本信息";
		//let 局部变量   var 全局变量
		let  action='${ctx}/bookAction.action?methodName=addBook';
		if(s){
			title="修改书本信息";
			action='${ctx}/bookAction.action?methodName=updateBook';
		}
		
		$('#dd').dialog({    
		    title: title,    
		    width: 400,    
		    height: 300,    
		    closed: false,    
		    cache: false,    
		    href: 'editBook.jsp',    
		    modal: true ,
		    buttons:[
		    	{
		    		text:'保存',
		    		handler:function(){
		    			$.ajax({
		    				url: action,
		    				type: 'post',
		    				data: $("#bookform").serialize(),
		    				dataType: "JSON",
		    				success: function(data){
		    					if(data.success){
		    						$.messager.alert('消息',data.msg,'info');
		    						qryBook();
		    						$("#dd").dialog("close");//关闭窗口
		    					}
		    				},
		    				error:function(error){//如果增加错误
		    					console.log(error);
		    				}
		    			})
		    		}
		    	},
		    	   {
		    		text:"取消",
		    	handler:function(){
		    		$("#dd").dialog("close");//关闭窗口
		    	    }
		    	}
		    ],
		    onLoad : function(){
		    	$("#booktype").combobox({
		    		url : '${ctx}/bookAction.action?methodName=getBookTyepAll',
		    		valueField : 'typeId',
		    		textField : 'typeDesc'
		    	});
		    	if(s){
		    		$("#bookform").form("reset");//清空
		    		$("#bookform").form('load',s);		    		
		    	}
		    }
		});   
	}
	$("#bookdel").click(function(){
		let  s=$("#booktable").datagrid('getSelected');
		if(!s){
			$.messager.alert('消息','请选择要删除的记录','info');
			return  ;
		}
		
		$.messager.confirm('确认','确认删除吗',function(r){
			if(r){
				$.ajax({
					url: '${ctx}/bookAction.action?methodName=delBook',
					type: 'post',
					data:{
						id:s.id
					},
					dataType:'JSON',
					success:function(data){
						if(data.success){
							$.messager.alert('消息',data.msg,'info');
							qryBook();
						}
					}
				})
			}
		});
		
	})
	
});

</script>

</body>
</html>

 editBook.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<form  id="bookform">
     <input type="hidden" name="id"/>

    <div  style="margin-top:30px; text-align:center">
         <label>书名</label>
     <input name="bookname" class="easyui-textbox"  style="width:200px"> 
   </div>
   <div  style="margin-top:20px; text-align:center">
         <label>价格</label>
     <input name="price" class="easyui-textbox"  style="width:200px"> 
   </div>
   <div  style="margin-top:20px; text-align : center">
         <label>类型</label>
     <!-- <input name="booktype" class="easyui-textbox"  style="width:200px">  -->
     <input  id="booktype" name="booktype"  value="请选择" style="width: 200px;" />
   </div>
</form>

 index.jsp

<%@ 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="common/head.jsp"%>
</head>


<body class="easyui-layout">

	<div data-options="region:'north',split:true" style="height: 80px; font-size: 40px; padding: 10px;">
		EasyUi后台管理系统
	</div>
	
	<div data-options="region:'west',title:'导航菜单',split:true" style="width: 240px;">
		<div id="menu" class="easyui-accordion" data-options="fit:true,border:false">   
		     
		</div>  
	</div>
	
	<div data-options="region:'center'" style="padding: 5px; background: #eee;">
	    <div id="funtab" class="easyui-tabs" data-options="fit:true">   
           <div title="首页" style="padding:20px;display:none;">   
            首页    
          </div>   
        </div>  
	</div>
	
	<div data-options="region:'south',split:true"style="height: 30px; text-align: center; background: #E0ECFF"class="panel-title">
		Copyright@XXXX有限责任公司
	</div>
	
</body>

<script>
$(function() {
	//发一个ajax请求
	$.ajax({
		url: '${ctx}/moduleAction.action?methodName=getModules',
		type: 'get', //提交类型是get的
		data: {  //
			pid: -1
		},
		dataType: 'JSON',//返回的类型
		
		//成功之后的回调函数
		success: function(data) {
			//循环生成一个上风琴效果
			$.each(data, function(index, m) {
				$('#menu').accordion('add', {
					title: m.text,
					content:'<ul id=' + m.id + ' alt=' + m.text + ' class="easyui-tree"></ul>',
					selected: false
				});
			});
			//动态生成一棵树
			$('#menu').accordion({
				//两个参数 index是序号
				onSelect: function(title,index) {
					let obj = $("ul[alt="+title+"]");
					let pid = obj.attr("id");//获取子菜单
					//避免重复加载
					if(obj.tree("getRoots").length > 0) return;
					//如果没有生成就生成一个
					obj.tree({
						url: '${ctx}/moduleAction.action?methodName=getModules',
						queryParams:{
							pid:pid
						},
						onClick: function(node){
							//判断是否存在 
							if($("#funtab").tabs("exists",node.text)) {
								//回到新建的选项卡
								$("#funtab").tabs("select",node.text);
								return;
							} ;
							
							$('#funtab').tabs('add',{    
							title:node.text,
							closable:true,
							content:'<iframe frameborder=0 style="width:100%; height:100%"  src="'+node.url+'"/>' 
							
							});
						}
					})
				}
			});
			
		},
		
		error: function(error) {
			console.log(error);
		}
				
	})
})
</script>
</html>

         WEB-INF

          lib

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://xmlns.jcp.org/xml/ns/javaee"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
	id="WebApp_ID" version="3.1">
	<display-name>easyui_5</display-name>
	<!--中央控制器 -->
	<servlet>
		<servlet-name>ActionDispatchServlet</servlet-name>
		<servlet-class>org.lisen.mvc.framework.ActionDispatchServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>ActionDispatchServlet</servlet-name>
		<url-pattern>*.action</url-pattern>
	</servlet-mapping>


	<filter>
		<filter-name>EncodingFilter</filter-name>
		<filter-class>org.lisen.mvc.util.EncodingFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>EncodingFilter</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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值