简单的三层结构到数据库例子

这是一个关于如何使用JSP、Servlet、实体类、业务逻辑层和数据访问层实现简单的数据库操作的例子。示例中展示了添加、删除和分页查询书本订单的功能,涉及表单提交、数据封装、数据库交互和页面展示。
摘要由CSDN通过智能技术生成

1.数据库的数据表


2.jsp页面的代码(没样式)addBookOrder.jsp

//把jsp页面的数据用from表单提到Servlet插入数据库

<form action="AddBookOrderServlet?tag=add" method="post" id="AddBookOrder">
  <tbody>
    <tr>
      <td align="right">书本名称:</td>
      <td align="left" colspan="3"><input name="boname" type="text" id="tbx_short2" class="span1-1" />
        </td>
    </tr>
    <tr>
      <td align="right">书本数量:</td>
      <td align="left"><input name="bocount" type="text" id="manTextBox" class="span1-1" /></td>
    </tr>
    <tr>
      <td align="right">书本价格:</td>
      <td align="left" colspan="3"><input name="boprice" type="text" id="phoneTextBox" class="span1-1" /></td>
    </tr>
    <tr>
      <td align="right">是否购买:</td>
      <td align="left" colspan="3"><input name="boisbuy" type="text" id="phoneTextBox" class="span1-1" /></td>
    </tr>
  </tbody>
</table>
   </div>
<div class="modal-footer">
<button class="btn btn-info" data-dismiss="modal" aria-hidden="true" style="width:80px" οnclick="addBookOrder()" >添加</button> 
                     <button class="btn btn-info" data-dismiss="modal" aria-hidden="true" style="width:80px">取消</button> 
</div>
</div>
    </form>
   


//用table获取显示从数据库的数据
   <table class="table table-bordered table-striped table-hover">
     <tbody>
       <tr align="center">
         <td nowrap="nowrap"><strong>书本编号</strong></td>
         <td nowrap="nowrap"><strong>书本名称</strong></td>
         <td nowrap="nowrap"><strong>书本数量</strong></td>
         <td nowrap="nowrap"><strong>书本价格</strong></td>
         <td nowrap="nowrap"><strong>书本总价</strong></td>
         <td nowrap="nowrap"><strong>是否购买</strong></td>
         <td width="80" nowrap="nowrap"><strong> 操作 </strong></td>
         </tr>
          //用EL
         <c:forEach  items="${pu.list}" var="ord">
         <tr align="center">
         <td nowrap="nowrap">${ord.id}</td>
         <td nowrap="nowrap">${ord.boname}</td>
         <td nowrap="nowrap">${ord.bocount}</td>
          <td nowrap="nowrap">${ord.boprice}</td>
         <td nowrap="nowrap">${ord.bosumprice}</td>
         <td nowrap="nowrap">${ord.boisbuy}</td>
           <td>
             <a href='AddBookOrderServlet?tag=del&id=${ord.id}' 
                οnclick='return confirm("你确定要删除 ${ord.boname} 吗")'>删除订单</a>
           </td>
         </tr>
       </c:forEach>
     </tbody>
     //分页,用来获取数据库的信息,
     <table  class="margin-bottom-20 table  no-border" >
     <tr>
       <td class="text-center">总记录数  ${pu.pageNumber} 条, 共 ${pu.countPage} 页,当前第  ${pu.indexPage} 页  </td>
       <td class="text-center"><a href='AddBookOrderServlet'><span class="btn btn-info" style="width:80px;" >首 页</span></a></td>
       <td class="text-center"><span><a href="AddBookOrderServlet?indexPage=${pu.indexPage>1?pu.indexPage-1:1 }"><input type="button" value="上一页" class="btn btn-info" style="width:80px;" ></a></span></td>
      <td class="text-center"><span><a href="AddBookOrderServlet?indexPage=${pu.indexPage<pu.countPage?pu.indexPage+1:pu.countPage }"><input type="button" value="下一页" class="btn btn-info" style="width:80px;" ></a></span></td>
     
       <td class="text-center"><a href='AddBookOrderServlet?indexPage=${pu.countPage}'><span class="btn btn-info" style="width:80px;" > 尾页</span></a></td>
    </tr> 
 </table>

3.实体类

package com.etc.entity;


public class BookOrder {


private int id;
private String boname;
private int bocount;
pri

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值