网学网为广大网友收集整理了,JSP开发一个客户关系管理系统,希望对大家有所帮助!
客服咨询,网学网竭诚为您服务,本站永久域名:myeducs.cn |
5.3 持久层的实现 在持久层(dao层文件夹)中,主要有两种类,一个是接口(interface)类,类名以Dao结尾,另一个是接口的实现类,类名以DaoImpl结尾,其中企业类型设置模块的代码如下: 1.接口类(以Dao为结尾的类名) /*********************************** CqylxDao.java********************************/ package com.dao; import java.util.List; import com.domain.CqylxForm; public interface CqylxDao { public List qylxSelect(); public void qylxDelete(CqylxForm qylx); public void qylxupdate(CqylxForm qylx); public CqylxForm qylxSelectOne(CqylxForm qylx); public void qylxInsert(CqylxForm qylx); public int qulxCount(); } 2.实现接口类(以DaoImpl为结尾的类名) /****************************** CqylxDaoImpl.java**********************************/ package com.dao; import java.util.List; import java.util.ArrayList; import com.tool.JDBConnection; import com.tool.SQLCode; import java.sql.ResultSet; import java.sql.*; import com.domain.CqylxForm; //加载类 //对表tb_Client_qylx的操作 public class CqylxDaoImpl implements CqylxDao { public List qylxSelect() { //查询的操作 JDBConnection connection = new JDBConnection(); CqylxForm form = null; List list = new ArrayList(); // ArrayList类实现了List接口 String sql = SQLCode.getSQLCode("sql.qylx.select"); try { ResultSet rs = connection.executeQuery(sql); while (rs.next()) { form = new CqylxForm(); form.setQylx_id(rs.getString(1)); form.setQylx_lxmc(rs.getString(2)); form.setQylx_bz(rs.getString(3)); list.add(form); } } catch (SQLException ex) { } connection.close(); return list; } //删除操作 public void qylxDelete(CqylxForm qylx) { JDBConnection connection = new JDBConnection(); String sql = SQLCode.getSQLCode("sql.qylx.delete"); sql = connection.editSqlCode(sql, qylx.getQylx_id()); connection.executeUpdate(sql); connection.close();} //修改操作 public void qylxupdate(CqylxForm qylx) { JDBConnection connection = new JDBConnection();//利用对象connection调用JDBConnection类中方法 String sql = SQLCode.getSQLCode("sql.qylx.update"); sql = connection.editSqlCode(sql, qylx.getQylx_lxmc()); sql = connection.editSqlCode(sql, qylx.getQylx_bz()); sql = connection.editSqlCode(sql, qylx.getQylx_id()); connection.executeUpdate(sql); connection.close(); } //以企业类型的编号进行查找 public CqylxForm qylxSelectOne(CqylxForm qylx) { JDBConnection connection = new JDBConnection(); CqylxForm form = null; String sql = SQLCode.getSQLCode("sql.qylx.selectOne"); sql = connection.editSqlCode(sql, qylx.getQylx_id()); try { ResultSet rs = connection.executeQuery(sql); while (rs.next()) { form = new CqylxForm(); form.setQylx_id(rs.getString(1)); form.setQylx_lxmc(rs.getString(2)); form.setQylx_bz(rs.getString(3)); } } catch (SQLException ex) { } connection.close(); return form; } //添加操作 public void qylxInsert(CqylxForm qylx) { JDBConnection connection = new JDBConnection(); String sql = SQLCode.getSQLCode("sql.qylx.insert"); sql = connection.editSqlCode(sql, qylx.getQylx_id()); sql = connection.editSqlCode(sql, qylx.getQylx_lxmc()); sql = connection.editSqlCode(sql, qylx.getQylx_bz()); connection.executeUpdate(sql); connection.close(); } //在数据库中查找最大的流水号,然后返回加1,此数据用于企业类型编号存储,表现了编号的唯一性 public int qulxCount() { int iCount = 0; JDBConnection connection = null; connection = new JDBConnection(); String sql = SQLCode.getSQLCode("sql.qylx.count"); ResultSet rs = null; try { rs = connection.executeQuery(sql); while (rs.next()) { CqylxForm form = new CqylxForm(); iCount = rs.getInt("t"); } } catch (SQLException ex) { } connection.close(); return iCount+1; }} 5.4 服务层的实现 通过服务层(server文件夹)的方法,可以使持久层(dao)的功能能够具体实现。在服务层中(在server文件夹)类和持久层中类存在方式是一样的。但是,接口类是以Façade为结尾的类名,实现接口类是以FacadeImpl为结尾的类名。 1.接口类(以Facade为结尾的类名) /********************************** CqylxFacade.java*******************************/ package com.service; import java.util.List; import com.domain.CqylxForm; public interface CqylxFacade { public List qylxSelect(); …………………………..// 这段代码和dao层中的接口类是一样的 public int qulxCount(); } 2.实现接口类(以FacadeImpl为结尾的类名) /******************************** CqylxFacadeImpl.java******************************/ package com.service; import java.util.List; import com.dao.CqylxDao; import com.dao.CqylxDaoImpl; import com.domain.CqylxForm; public class CqylxFacadeImpl implements CqylxFacade { private CqylxDao qylx = null; public CqylxFacadeImpl() { this.qylx = new CqylxDaoImpl(); } public List qylxSelect() { return this.qylx.qylxSelect(); } public void qylxDelete(CqylxForm qylx) { this.qylx.qylxDelete(qylx); } public void qylxupdate(CqylxForm qylx) { this.qylx.qylxupdate(qylx); } public CqylxForm qylxSelectOne(CqylxForm qylx) { return this.qylx.qylxSelectOne(qylx); } public void qylxInsert(CqylxForm qylx) { this.qylx.qylxInsert(qylx); } public int qulxCount() { return this.qylx.qulxCount(); } } 5.5 企业类型设置控制层的实现 在控制层中(在webtier文件夹),类的实现是在jsp页面中进行调用,下面结合jsp页中的代码,说明通过类实现的过程。 1.添加操作 添加企业类型信息分为两个步骤: (1)添加数据之前首先查询企业类型信息数据表中的最大流水号,然后加1作为新的企业类型编号,并在添加页面中以隐藏域表示。 (2)执行添加功能。 查询最大流水号类的代码如下: /******************************** CqylxCountID.java *******************************/ package com.webtier.clientQylxAction; public class CqylxCountID extends Action { private CqylxFacade qylx = null; public CqylxCountID() { this.qylx = new CqylxFacadeImpl(); //实现服务层的方法 } public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { String changeType = String.valueOf(this.qylx.qulxCount()); httpServletRequest.setAttribute("changeType", changeType); //将查出的数据转换为String类型 return actionMapping.findForward("cqylxCountID"); } } |
本站发布的计算机毕业设计均是完整无错的全套作品,包含开题报告+程序+论文+源代码+翻译+答辩稿PPT |
本文选自计算机毕业设计http://myeducs.cn |