資源簡介
java web 使用servlet進行增刪改查,頁面進行分頁處理。

代碼片段和文件信息
package?dao;
import?cn.itcast.jdbc.TxQueryRunner;
import?domain.Customer;
import?domain.PageBean;
import?org.apache.commons.dbutils.QueryRunner;
import?org.apache.commons.dbutils.handlers.BeanHandler;
import?org.apache.commons.dbutils.handlers.BeanListHandler;
import?org.apache.commons.dbutils.handlers.ScalarHandler;
import?java.util.ArrayList;
import?java.util.List;
public?class?CustomerDao
{
????private?QueryRunner?qr=new?TxQueryRunner();
????public?void?add(Customer?c)
????{
????????try?{
????????????String?sql?=?“insert?into?t_customer?values(??????)“;
????????????object[]?params?=?{c.getId()?c.getName()?c.getGender()
????????????????????c.getPhone()?c.getEmail()?c.getDescription()};
????????????qr.update(sql?params);
????????}catch?(Exception?e)
????????{
????????????throw?new?RuntimeException(e);
????????}
????}
//????public?List?findAll()
//????{
//????????try{
//????????????String?sql=“select?*?from?t_customer“;
//????????????return?qr.query(sqlnew?BeanListHandler(Customer.class));
//????????}catch?(Exception?e)
//????????{
//????????????throw?new?RuntimeException(e);
//????????}
//????}
????public?PageBean?findAll(int?pc?int?pr)
????{
????????try{
????????????/*
?????????????*1.他需要創建pageBean對象pb
?????????????*?2.設置pb的pc和pr
?????????????*?3.得到tr,設置給pb
?????????????*?4.得到beanList設置給pb
?????????????*?最后返回給pb
?????????????*/
????????????PageBean?pb=new?PageBean<>();
????????????pb.setPc(pc);
????????????pb.setPr(pr);
????????????String?sql=“select?count(*)?from?t_customer“;
????????????Number?number=(Number)?qr.query(sqlnew?ScalarHandler<>());
????????????int?tr=number.intValue();
????????????pb.setTr(tr);
????????????sql=“select?*?from?t_customer?order?by?name?limit???“;
????????????object[]?params={(pc-1)*prpr};
????????????List?beanList=qr.query(sqlnew?BeanListHandler<>(Customer.class)params);
????????????pb.setBeanList(beanList);
????????????return?pb;
????????}catch?(Exception?e)
????????{
????????????throw?new?RuntimeException(e);
????????}
????}
????public?Customer?find(String?id)
????{
????????try?{
????????????String?sql?=?“select?*?from?t_customer?where?id=?“;
????????????return?qr.query(sql?new?BeanHandler(Customer.class)?id);
????????}catch?(Exception?e)
????????{
????????????throw?new?RuntimeException(e);
????????}
????}
????public?void?edit(Customer?customer)
????{
????????try{
????????????String?sql=“update?t_customer?set?name=?gender=?phone=?email=?description=??where?id=?“;
????????????object[]?params={customer.getName()customer.getGender()customer.getPhone()customer.getEmail()customer.getDescription()customer.getId()};
????????????qr.update(sqlparams);
????????}catch?(Exception?e)
????????{
????????????throw?new?RuntimeException(e);
????????}
????}
????public?void?delete(String?id)
????{
????????try?{
????????????String?sql?=?“delete?from?t_customer?where?id=?“;
????????????qr.update(sql?id);
????????}catch?(Exception
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????642??2017-12-27?20:58??manager\.idea\artifacts\manager_war_exploded.xm
?????文件????????200??2017-12-27?20:56??manager\.idea\encodings.xm
?????文件????????457??2017-12-27?20:57??manager\.idea\libraries\lib.xm
?????文件????????284??2017-12-27?20:57??manager\.idea\misc.xm
?????文件????????254??2017-12-27?20:56??manager\.idea\modules.xm
?????文件??????67080??2018-01-14?16:24??manager\.idea\workspace.xm
?????文件?????290564??2018-01-14?16:39??manager\customer.sql
?????文件?????497865??2017-07-18?18:58??manager\lib\c3p0-0.9.5.2.jar
?????文件?????246174??2017-07-18?18:58??manager\lib\commons-beanutils-1.9.3.jar
?????文件?????588337??2017-07-18?18:58??manager\lib\commons-collections-3.2.2.jar
?????文件??????77857??2017-07-18?18:58??manager\lib\commons-dbutils-1.6.jar
?????文件??????61829??2017-07-18?18:58??manager\lib\commons-logging-1.2.jar
?????文件??????25277??2017-07-18?18:58??manager\lib\itcast-tools-1.4.jar
?????文件?????414240??2017-07-18?18:58??manager\lib\jstl-1.2.jar
?????文件?????606472??2017-07-18?18:58??manager\lib\mchange-commons-java-0.2.11.jar
?????文件?????540852??2017-07-18?18:58??manager\lib\mysql-connector-java-5.0.8-bin.jar
?????文件?????176916??2012-02-17?14:13??manager\lib\servlet-api.jar
?????文件????????911??2017-12-27?20:57??manager\manager.iml
?????文件???????2316??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\add.jsp
?????文件???????2620??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\edit.jsp
?????文件????????496??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\fr
?????文件????????256??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\index.jsp
?????文件???????2579??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\list.jsp
?????文件????????346??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\msg.jsp
?????文件???????1743??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\query.jsp
?????文件????????765??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\top.jsp
?????文件????????568??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\WEB-INF\classes\c3p0-config.xm
?????文件???????5251??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\WEB-INF\classes\dao\CustomerDao.class
?????文件???????1429??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\WEB-INF\classes\Demo\Demo.class
?????文件???????1450??2018-01-05?13:45??manager\out\artifacts\manager_war_exploded\WEB-INF\classes\domain\Customer.class
............此處省略73個文件信息
評論
共有 條評論