easyui实现数据的增、删、改

一、前言

上次分享了easyui实现数据查询,今天分享easyui实现数据增、删、改

二、实现

1、后端代码编写

增加dao方法

package com.liubiao.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.liubiao.entity.Book;
import com.liubiao.entity.Permission;
import com.liubiao.util.BaseDao;
import com.liubiao.util.BuildTree;
import com.liubiao.util.PageBean;
import com.liubiao.util.PinYinUtil;
import com.liubiao.util.StringUtils;
import com.liubiao.vo.TreeVo;

public class BookDao extends BaseDao<Book> {
   
	
	/**
	 * 是直接从数据库获取到的数据
	 * @param permission
	 * @param pageBean
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws SQLException+
	 */
	public List<Book> list(Book book,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
   
		String name = book.getName();
		String sql="select * from t_easyui_book where true ";
		if(StringUtils.isNotBlank(name)) {
   
			sql+=" and name like '%"+name+"%'";
		}
		return super.executeQuery(sql, Book.class, pageBean);
	}
	
//	增加
	public int add(Book book) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
   
		book.setPinyin(PinYinUtil.getAllPingYin(book.getName()));
		String sql = "insert into t_easyui_book values(null,?,?,?,?,?,?,?,?,?,?,?)";
		return super.executeUpdate(sql, book, new String[] {
   "name","pinyin","cid","author","price","image","publishing","description","state","deployTime","sales"});
	}
	
//	修改
	public int edit(Book book) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
   
		book.setPinyin(PinYinUtil.getAllPingYin(book.getName()));
		String sql = "update t_easyui_book set name=?,pinyin=?,cid=?,author=?,price=?,image=?,publishing=?,description=?,state=?,deployTime=?,sales=? where id=? ";
		return super.executeUpdate(sql, book, new String[] {
   "name","pinyin","cid","author","price","image","publishing","description","state","deployTime","sales","id"});
	}
	
//	删除
	public int del(Book book) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
   
		String sql = "delete from t_easyui_book where id=?";
		return super.executeUpdate(sql, book, new String[] {
   "id"});
	}
	
}

数据处理的类

package com.liubiao.web
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值