JavaEE企業(yè)級(jí)項(xiàng)目開發(fā)(第3版)課件 微課6-2:任務(wù)6.1添加申請(qǐng)?jiān)O(shè)計(jì)_第1頁(yè)
JavaEE企業(yè)級(jí)項(xiàng)目開發(fā)(第3版)課件 微課6-2:任務(wù)6.1添加申請(qǐng)?jiān)O(shè)計(jì)_第2頁(yè)
JavaEE企業(yè)級(jí)項(xiàng)目開發(fā)(第3版)課件 微課6-2:任務(wù)6.1添加申請(qǐng)?jiān)O(shè)計(jì)_第3頁(yè)
JavaEE企業(yè)級(jí)項(xiàng)目開發(fā)(第3版)課件 微課6-2:任務(wù)6.1添加申請(qǐng)?jiān)O(shè)計(jì)_第4頁(yè)
JavaEE企業(yè)級(jí)項(xiàng)目開發(fā)(第3版)課件 微課6-2:任務(wù)6.1添加申請(qǐng)?jiān)O(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀 繼續(xù)免費(fèi)閱讀

付費(fèi)下載

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

主講人:石云延遲符添加申請(qǐng)?jiān)O(shè)計(jì)Spring的數(shù)據(jù)庫(kù)開發(fā)與事務(wù)添加申請(qǐng)?jiān)O(shè)計(jì)

添加申請(qǐng)是工作流轉(zhuǎn)的基礎(chǔ)模塊,主要功能是編輯公文,提交給指定部門審批。添加申請(qǐng)的設(shè)計(jì)應(yīng)用Servlet與Spring框架結(jié)合的方式開發(fā),用戶在視圖層頁(yè)面輸入申請(qǐng)標(biāo)題、申請(qǐng)內(nèi)容,Servlet控制層獲取輸入的申請(qǐng)信息,并調(diào)用模型層的服務(wù)方法將申請(qǐng)信息保存到數(shù)據(jù)庫(kù)中,最后調(diào)用顯示所有申請(qǐng)的方法返回到所有申請(qǐng)頁(yè)面。添加申請(qǐng)?jiān)O(shè)計(jì)

添加申請(qǐng)實(shí)施分為5個(gè)步驟:DAO層、Service層、Servlet控制層、視圖層、applicationContex.xml文件配置。本任務(wù)重點(diǎn)介紹DAO層實(shí)現(xiàn)類的設(shè)計(jì)、Servlet控制類的設(shè)計(jì)。添加申請(qǐng)DAO層實(shí)現(xiàn)類添加申請(qǐng)DAO層中添加申請(qǐng)方法中使用了JdbcTemplate類,通過(guò)執(zhí)行jdbcTemplate.update()方法保存數(shù)據(jù),參數(shù)通過(guò)PreparedStatement對(duì)象傳遞。//添加申請(qǐng)數(shù)據(jù)訪問(wèn)層實(shí)現(xiàn)類@Data@ComponentpublicclassApplyDAOimplementsIApplyDAO{ @Autowired privateJdbcTemplatejdbcTemplate; @Autowired privateDataSourcedataSource; @Autowired privateDataSourceTransactionManagertransactionManager; privateDefaultTransactionDefinitiondef;//獲得所有申請(qǐng)publicListgetAllApply(){Stringsql="select*fromtb_application";ListapplyList=jdbcTemplate.queryForList(sql);returnapplyList;}添加申請(qǐng)DAO層實(shí)現(xiàn)類增加申請(qǐng)方法,主要步驟://增加申請(qǐng)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;}}}添加申請(qǐng)控制Servlet類添加申請(qǐng)控制類負(fù)責(zé)接收用戶輸入的申請(qǐng)信息,調(diào)用申請(qǐng)服務(wù)類添加申請(qǐng)方法保存申請(qǐng)信息到數(shù)據(jù)庫(kù)表中,為了能查看已經(jīng)有的申請(qǐng),調(diào)用查詢所有的申請(qǐng)方法,最后返回到顯示所有申請(qǐng)的頁(yè)面。@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")){//添加申請(qǐng)SimpleDateFormatsf=newSimpleDateFormat("yyyy-MM-dd");//獲取申請(qǐng)時(shí)間

Applyapply=newApply();//創(chuàng)建Apply對(duì)象apply.setTitle(title);......//調(diào)用申請(qǐng)服務(wù)方法保存申請(qǐng)booleanresult=applyService.addApply(apply);if(result){res.sendRedirect(this.showAllApply(req));}else{res.sendRedirect("error.jsp");}}}添加申請(qǐng)控制Servlet類獲取所有申請(qǐng)方法,主要步驟://獲取所有申請(qǐng)publicStringshowAllApply(HttpServletRequestreq){Listapplylist=applyService.getAllApply();ListapplicationList=newArrayList();//將applylist中的Map轉(zhuǎn)換為Apply對(duì)象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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論