书籍新增&类别下拉框&上下架

一,书籍新增界面类别下拉框

1.1:根据下拉框类型写实体类:

 


 1.2 查询所有类型的方法

	public List<Category> listType(Category category,PageBean pageBean) throws Exception{
		String sql="select * from t_easyui_category where 1=1";
		return executeQuery(sql, Category.class, pageBean);
	}

 1.3 子控制器(CategoryAction

package com.xyy.web;

import java.util.List;

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

import com.xyy.dao.CategoryDao;
import com.xyy.entity.Category;
import com.zking.framework.ActionSupport;
import com.zking.framework.ModelDriver;
import com.zking.util.ResponseUtil;

public class CategoryAction extends ActionSupport implements ModelDriver<Category>{

	public Category category=new Category();
	public CategoryDao categoryDao=new CategoryDao();
	@Override
	public Category getModel() {
		return category;
	}
	
	public String listType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
		List<Category> listType = categoryDao.listType(category, null);
		ResponseUtil.writeJson(resp, listType);
		return null;
	}
} 

1.4在点击菜单栏需弹出一个增加的窗口

$(function(){
    $("#bookMenus").tree({
        url:$("#ctx").val()+"/permission.action?methodName=tree",
//        给菜单栏一个点击
        onClick: function(node){
//            判断面板是否存在
            var exists=$("#bookTabs").tabs('exists',node.text);
            if(exists){
                $("#bookTabs").tabs('select',node.text);
            }else{
                $('#bookTabs').tabs('add',{    
                    title:node.text,    
                    content:'<iframe width="100%" height="100%" src="'+$("#ctx").val()+node.attributes.self.url+'" />',    
                    closable:true
                }); 
            }
        }
    });
})

1.5 通过数据库内的类型传到增加窗口的下拉框,使其灵活性

借助API中的ComboBox(下拉列表框)

 <input id="cid" name="cid" value="" label="类别" >

js文件: 

   $(function () {
        $('#cid').combobox({    
            url:'${pageContext.request.contextPath}/category.action?methodName=combobox',                valueField:'id',    
            textField:'text'   
        });  

    });

效果展示:

 

二,书籍新增

2.1书籍实体类:

//    查询时间的时候用这个格式

@JsonFormat(pattern="yyyy-mm-dd HH:mm:ss",timezone="GMT+8")
  private Date deployTime;


2.2bookDao

public void add( Book t) throws Exception {
//        转化拼音
        t.setPinyin(PinYinUtil.getAllPingYin(t.getName()));
        t.setDeployTime(new Date());
        String sql="insert into t_easyui_book(name,pinyin,cid,author,price,image,publishing,description,state,deployTime,sales) values(?,?,?,?,?,?,?,?,?,?,?)";
        super.executeUpdate(sql, 
                t, new String[] {"name","pinyin","cid","author","price","image","publishing","description","state","deployTime","sales"});
    }

2.3 bookAction

public void add(HttpServletRequest req, HttpServletResponse resp) {
        try {
            bd.add(book);
            ResponseUtil.writeJson(resp, 1);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                ResponseUtil.writeJson(resp, 0);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }

2.4 获取数据,提交表单

/*     通过form控件提交 */
    function submitForm() {
        $('#ff').form('submit', {    
            url:'${pageContext.request.contextPath}/book.action?methodName=add',    
            success:function(data){    
                if(data==1){
                    $('#ff').form('clear');
                }
            }    
        });  

    }
    /* 刷新 */
    function clearForm() {
        $('#ff').form('clear');
    }

效果展示:

新增的书籍在未上架中。

三,上架&下架

3.1 上架其实就是修改书籍属性

    public List<Book> list(Book book, PageBean pageBean) throws Exception {
        String sql="select * from t_easyui_book where 1=1";
        String name=book.getName();
        int state = book.getState();
        if(StringUtils.isNotBlank(name)) {
            sql+=" and name like '%"+name+"%'";
        }
        if(state!=0) {
            sql+=" and state ="+state;
        }
        return super.executeQuery(sql, Book.class, pageBean);
    }

//    上下架
    public void editStatus(Book book) throws Exception {
        super.executeUpdate("update t_easyui_book set state=?  where id=?", 
                book,new String[] {"state","id"});
    }

3.2 子控制器

public void list(HttpServletRequest req, HttpServletResponse resp) {
        PageBean pageBean=new PageBean();
        pageBean.setRequest(req);
        try {
            List<Book> list = bd.list(book, pageBean);
            ResponseUtil.writeJson(resp, new R().data("total", pageBean.getTotal())
                    .data("rows", list));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

//    如果上架,书籍的状态改为2
//    如果下架,书籍的状态改为3
    public void editStatus(HttpServletRequest req, HttpServletResponse resp) {
        try {
            bd.editStatus(book);
            ResponseUtil.writeJson(resp, 1);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                ResponseUtil.writeJson(resp, 0);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

3.3 JS文件

function shangjia() {
        $.messager.confirm('确认','您确认想要上架此书籍吗?',function(r){
            if (r){
                var row = $('#dg').datagrid('getSelected');
                if (row){
                    $.ajax({
                        url:'${pageContext.request.contextPath}/book.action?methodName=editStatus&state=2&id=' + row.id,
                        success:function (data) {
                                                    }
                    })
                } 
            }
        });

    }

根据状态的不同,改变上下架

function xiajia() {
        $.messager.confirm('确认','您确认想要下架此书籍吗?',function(r){
            if (r){
                var row = $('#dg').datagrid('getSelected');
                if (row){
                    $.ajax({
                        url:'${pageContext.request.contextPath}/book.action?methodName=editStatus&state=3&id=' + row.id,
                        success:function (data) {
                            $('#dg').datagrid('reload');    // 重新载入当前页面数据  

                        }
                    })
                }
            }
        });

    }

效果展示:已上架&已下架

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值