自定义mvc02

这篇博客详细介绍了如何使用自定义MVC框架实现书籍管理功能,包括书籍类别下拉框、新增与修改书籍以及书籍的上下架操作。通过实体类、DAO包和Web包的配置,以及JavaScript和jQuery的交互,实现了数据的增删改查。同时,展示了界面的交互设计和AJAX请求的使用。
摘要由CSDN通过智能技术生成

思维导图

 先给界面中添加Tabs选项卡

$(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
				});  
 
			}
		}
	});
})

 

一.书籍类别下拉框

①实体类,dao包以及web包

package com.lsy.entity;
 
public class Category {
	private long id;
	private String name;
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Category [id=" + id + ", name=" + name + "]";
	}
	
}

dao包(查出所有类别)

package com.lsy.dao;
 
import java.util.List;
 
import com.lsy.entity.Category;
import com.zking.util.BaseDao;
import com.zking.util.PageBean;
 
public class CategoryDao extends BaseDao<Category>{
	
	public List<Category> list(Category category, PageBean pageBean) throws Exception {
		String sql="select * from t_easyui_category";
		return super.executeQuery(sql, Category.class, pageBean);
	}
}	

web包

package com.lsy.web;
 
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.lsy.dao.CategoryDao;
import com.lsy.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>{
	private Category category=new Category();
	private CategoryDao categoryDao=new CategoryDao();
	
	@Override
	public Category getModel() {
		return category;
	}
	
	/**
	 * 书籍类别下拉框
	 * @param req
	 * @param resp
	 * @return
	 */
	public String combobox(HttpServletRequest req, HttpServletResponse resp) {
		try {
			List<Category> list = categoryDao.list(category, null);
			ResponseUtil.writeJson(resp, list);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
}

 

配置xml文件

<action path="/category" type="com.lsy.web.CategoryAction">
    </action>

addBook.jsp界面代码

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

    });

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>书籍新增</title>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/static/js/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/js/easyui/themes/icon.css">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/js/easyui/jquery.easyui.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/main.js"></script>
</head>
<body>
<div style="margin:20px 0;"></div>
<div class="easyui-panel" title="已下架书籍" style="width:100%;padding:30px 60px;">
    <form id="ff" action="" method="post">
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="name" style="width:100%" data-options="label:'书名:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input id="cid" name="cid" value="" label="类别" >
            <!-- <select class="easyui-combobox" name="cid" label="类别" style="width:100%">
                <option value="1">文艺</option>
                <option value="2">小说</option>
               <option value="3">青春</option>
            </select> -->
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="author" style="width:100%" data-options="label:'作者:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="price" style="width:100%"
                   data-options="label:'价格:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="publishing" style="width:100%"
                   data-options="label:'出版社:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="description" style="width:100%;height:60px"
                   data-options="label:'简介:',required:true">
        </div>
        <%--默认未上架--%>
        <input type="hidden" name="state" value="1">
        <%--默认起始销量为0--%>
        <input type="hidden" n
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值