




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
主讲人:石云延迟符添加申请设计Spring的数据库开发与事务添加申请设计
添加申请是工作流转的基础模块,主要功能是编辑公文,提交给指定部门审批。添加申请的设计应用Servlet与Spring框架结合的方式开发,用户在视图层页面输入申请标题、申请内容,Servlet控制层获取输入的申请信息,并调用模型层的服务方法将申请信息保存到数据库中,最后调用显示所有申请的方法返回到所有申请页面。添加申请设计
添加申请实施分为5个步骤:DAO层、Service层、Servlet控制层、视图层、applicationContex.xml文件配置。本任务重点介绍DAO层实现类的设计、Servlet控制类的设计。添加申请DAO层实现类添加申请DAO层中添加申请方法中使用了JdbcTemplate类,通过执行jdbcTemplate.update()方法保存数据,参数通过PreparedStatement对象传递。//添加申请数据访问层实现类@Data@ComponentpublicclassApplyDAOimplementsIApplyDAO{ @Autowired privateJdbcTemplatejdbcTemplate; @Autowired privateDataSourcedataSource; @Autowired privateDataSourceTransactionManagertransactionManager; privateDefaultTransactionDefinitiondef;//获得所有申请publicListgetAllApply(){Stringsql="select*fromtb_application";ListapplyList=jdbcTemplate.queryForList(sql);returnapplyList;}添加申请DAO层实现类增加申请方法,主要步骤://增加申请publicbooleanaddApply(Applyapply){finalStringtitle=apply.getTitle();finalStringapplyContent=apply.getApplyContent();finalStringapplyDate=apply.getApplyDate();finalintuserId=apply.getUserId();finalintdepartId=apply.getDepartId();finalStringapprovePerson=apply.getApprovePerson();finalStringapproveDate=apply.getApplyDate();finalStringapproveView=apply.getApproveView();finalintstatus=apply.getStatus();
inti=jdbcTemplate.update(newPreparedStatementCreator(){publicPreparedStatementcreatePreparedStatement(Connectioncon)throwsSQLException{Stringsql="insertintotb_applicationvalues(?,?,?,?,?,?,?,?,?)";PreparedStatementps=con.prepareStatement(sql);ps.setString(1,title); ps.setString(2,applyContent); ps.setString(3,applyDate); ps.setInt(4,userId); ps.setInt(5,departId); ps.setString(6,approvePerson); ps.setString(7,approveDate); ps.setString(8,approveView); ps.setInt(9,status); returnps;}});if(i>0){returntrue;}else{returnfalse;}}}添加申请控制Servlet类添加申请控制类负责接收用户输入的申请信息,调用申请服务类添加申请方法保存申请信息到数据库表中,为了能查看已经有的申请,调用查询所有的申请方法,最后返回到显示所有申请的页面。@WebServlet("/applyController")publicclassApplyControllerextendsHttpServlet{IApplyServiceapplyService=null;publicvoidinit(ServletConfigservletConfig)throwsServletException{ServletContextsc=servletConfig.getServletContext();WebApplicationContextwac=WebApplicationContextUtils.getWebApplicationContext(sc);applyService=wac.getBean("applyService",ApplyService.class);}protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseres)throwsServletException,IOException{……if(action.equals("add")){//添加申请SimpleDateFormatsf=newSimpleDateFormat("yyyy-MM-dd");//获取申请时间
Applyapply=newApply();//创建Apply对象apply.setTitle(title);......//调用申请服务方法保存申请booleanresult=applyService.addApply(apply);if(result){res.sendRedirect(this.showAllApply(req));}else{res.sendRedirect("error.jsp");}}}添加申请控制Servlet类获取所有申请方法,主要步骤://获取所有申请publicStringshowAllApply(HttpServletRequestreq){Listapplylist=applyService.getAllApply();ListapplicationList=newArrayList();//将applylist中的Map转换为Apply对象Iteratorit=applylist.iterator();while(it.hasNext()){MapappMap=(Map)it.next();Applyapply=newApply();IntegerapplyId=(Integer)appMap.get("applyId");Stringtitle=(String)appMap.get("title");StringapplyContent=(String)appMap.get("applyContent");StringapplyDate=(String)appMap.get("applyDate");IntegeruserId=(Integer)appMap.get("userId");IntegerdepartId=(Integer)appMap.get("departId");Integerstatus=(Integer)appMap.get("status");apply.setApplyId(applyId);apply.setTitle(title);apply.setApplyDate(applyDate);apply.setUserId(userId);apply.setDepartId(departId);apply.setApproveView(approveView);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 创业公司股权转让合同
- 个人转租租房合同协议
- 住建委房屋租赁合同样本
- 短期临时运输合作协议2025
- Brand KPIs for pet supply online shop PetSmart in the United States-外文版培训课件(2025.2)
- 2025年度行政诉讼法知识竞赛题库及答案(共150题)
- 2025年度个人消费贷款担保合同样本
- 2025年度采购服务的合同
- 家居装修装饰工程合同管理
- 中药材购销合同范本2025年
- 铁路客车车辆电气系统维护考核试卷
- DB34∕T 4235-2022 浓香窖泥检测操作规程
- 统编版高中语文必修下:辨识媒介信息
- 2024年东南亚纸巾商销(AFH)市场深度研究及预测报告
- 服务质量保障措施及进度保障措施
- 七层垂直循环式立体车库
- 中国子宫内膜增生管理指南(2022)解读
- 酸枣仁汤的剂型研究
- 2022版义务教育(道德与法治)课程标准(附课标解读)
- 2021年国家公务员考试行测真题答案及解析
- 人口社会学(第二版) 课件 第八章 婚姻家庭
评论
0/150
提交评论