mysql jdbc 分层及三层以及jspservlet

本文介绍了一个图书管理系统的分层设计思路,包括实体类、业务逻辑层和服务实现层等关键部分,并展示了如何通过C3P0连接池进行数据库操作,以及如何在Servlet中处理HTTP请求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.创建数据库
2.创建表 添加数据
3.添加jar和c3p0的配置文件
4.搭建 三层
  com.vp.bean或者 com.vp.pojo
实体类和辅助类,接收数据和发送数据所使用的载体
  com.vp.service
业务逻辑层接口,增加功能
  com.vp.service.impl   这里其实是调用dao层的方法来实现
业务逻辑层接口实现类,实现功能//相当于表现层和数据访问层的缓冲区
  com.vp.dao
数据访问层接口,增加需求的功能
  com.vp.dao.impl  
数据访问层实现类,实现需求,直接访问数据库,并对数据库进行增删改查,并利用返回值进行反馈。
  com.vp.util
工具类
C3P0工具类以及其他工具类,主要用于减少代码冗余。
  com.vp.test   //调用业务逻辑层的实现类方法。
C3P0
  private static QueryRunner queryRunner;
    public static QueryRunner getQueryRunner(){
        //获取一个数据源
        DataSource dsource=new ComboPooledDataSource();
        //通过数据源初始化一个QueryRunner对象
        queryRunner=new QueryRunner(dsource);
        return queryRunner;
    }
 DAO层代码   private QueryRunner queryRunner =C3P0Util.getQueryRunner();//表示调用该方法,可以取代classforname和DriverManager.getConnection使用

测试类,表现层。

5.根据表创建实体类
6.在表现层中编写菜单
   例如:欢迎光临图书借阅系统
        1.查询所有图书信息
        2.根据条件查询所有图书信息
        3.根据图书编号查询该图书的详细信息
        6.查询所有图书类型信息

        4.新增图书
        5.根据图书编号删除图书信息
   
        6.根据图书类型编号删除图书类型
        7.根据图书编号修改图书信息
   
 
7.根据需求开始写代码
  (curd)
 

 

 

@WebServlet(name ="ibookServlet.htm", urlPatterns = "/ibookServlet.htm")
public class IbookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //中文乱码处理
        request.setCharacterEncoding("utf-8");
        String book_code = request.getParameter("book_code");//request.getParameter获得对应name的value
        String book_name = request.getParameter("book_name");
        String book_type = request.getParameter("book_type");
        String book_author = request.getParameter("book_author");
        String book_publish_press = request.getParameter("book_publish_press");
        String publish_date = request.getParameter("publish_date");
        System.out.println(book_type);
        int type = 0;
        if (book_type != null && !"".equals(book_type)) {
            type = Integer.parseInt(book_type);//强转
        }
        Book_InfoTable book_infoTable = new Book_InfoTable(book_code, book_name, type, book_author, book_publish_press, publish_date, 0);
        IBookServiceImpl iBookServiceimpl=new IBookServiceImpl();
        int add = iBookServiceimpl.add(book_infoTable);
        if (add>=1){
            response.sendRedirect("success.html");//最终返回到某个jsp网址。
        }else {
            response.sendRedirect("false.html");
        }
    }
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值