J2EE課程設計教學項目基于Struts2SpringHibernateSSH三大框架相互整合技術實現(xiàn)的數(shù)碼產(chǎn)品管理系統(tǒng)的實現(xiàn)實例第3部分_第1頁
J2EE課程設計教學項目基于Struts2SpringHibernateSSH三大框架相互整合技術實現(xiàn)的數(shù)碼產(chǎn)品管理系統(tǒng)的實現(xiàn)實例第3部分_第2頁
J2EE課程設計教學項目基于Struts2SpringHibernateSSH三大框架相互整合技術實現(xiàn)的數(shù)碼產(chǎn)品管理系統(tǒng)的實現(xiàn)實例第3部分_第3頁
J2EE課程設計教學項目基于Struts2SpringHibernateSSH三大框架相互整合技術實現(xiàn)的數(shù)碼產(chǎn)品管理系統(tǒng)的實現(xiàn)實例第3部分_第4頁
J2EE課程設計教學項目基于Struts2SpringHibernateSSH三大框架相互整合技術實現(xiàn)的數(shù)碼產(chǎn)品管理系統(tǒng)的實現(xiàn)實例第3部分_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、楊教授工作室 精心創(chuàng)作的優(yōu)秀程序員 職業(yè)提升必讀系列資料1.1 j2ee課程設計教學項目基于struts2+spring +hibernate(ssh)三大框架相互整合技術實現(xiàn)的數(shù)碼產(chǎn)品管理系統(tǒng)的實現(xiàn)實例(第3部分)1.1.1 將數(shù)據(jù)訪問組件也由spring進行對象管理1、修改action類中的代碼package com.px1987.sshwebshop.action;import java.util.arraylist;import javax.servlet.http.httpservletrequest;import org.apache.struts2.servletactionco

2、ntext;import com.opensymphony.xwork2.actionsupport;import er.productinfoserviceinterface;public class productinfomanage extends actionsupport productinfoserviceinterface productinfodaoserviceimple =null;public void setproductinfodaoserviceimple(productinfoserviceinte

3、rface productinfodaoserviceimple) ductinfodaoserviceimple = productinfodaoserviceimple;/* * 下面的factoryname代表查詢表單中提交的查詢條件 */private string factoryname=null;public string getfactoryname() return factoryname;public void setfactoryname(string factoryname) this.factoryname = factoryname;public pr

4、oductinfomanage() public string queryproductinfo()arraylist allproductinfo=productinfodaoserviceimple.doquesyproductinfo(factoryname);httpservletrequest request =servletactioncontext.getrequest();request.setattribute("allproductinfo", allproductinfo);return "gotoshowresult"2、修改pr

5、oductinfomanage類的queryproductinfo方法,刪除下面的對象創(chuàng)建的語句public string queryproductinfo () /oneproductinfoservicebean=new productinfodaoserviceimple();3、修改spring配置文件定義數(shù)據(jù)訪問組件<?xml version="1.0" encoding="utf-8"?><!doctype beans public "-/spring/dtd bean/en" "http:/w

6、/dtd/spring-beans.dtd"> <beans> <bean id="productinfomanage" class ="com.px1987.sshwebshop.action.productinfomanage" > <property name="productinfodaoserviceimple"> <ref bean ="productinfodaoserviceimple" />

7、 </property> </bean> <bean id="productinfodaoserviceimple" class ="com.px1987.sshwebshop.service.imple.productinfodaoserviceimple" > </bean></beans>4、再測試本示例的相關測試頁面查詢的結果與前面的結果一樣,只是不出現(xiàn)任何的錯誤。1.1.2 實現(xiàn)對數(shù)據(jù)庫表中的真實數(shù)據(jù)進行訪問操作1、修改productinfodaoserviceimple類中的doqu

8、esyproductinfo方法package com.px1987.sshwebshop.service.imple;import java.sql.connection;import java.sql.resultset;import java.sql.sqlexception;import java.util.arraylist;import javax.sql.datasource;import er.productinfoserviceinterface;import com.px1987.sshwebshop.ser

9、vice.pobject.productinfopo;public class productinfodaoserviceimple implements productinfoserviceinterface private datasource datasource=null;public void setdatasource (datasource datasource) this.datasource = datasource;public productinfodaoserviceimple() private connection con=null;public arraylist

10、 doquesyproductinfo(string factoryname) arraylist allproductinfo=new arraylist();resultset rs=null;trycon = datasource.getconnection();catch (sqlexception ex)system.out.println(ex.getmessage();string select_sqlstatement="select * from productinfo where factoryname=?"try try java.sql.prepar

11、edstatement pstmt = con.preparestatement(select_sqlstatement,resultset.type_scroll_sensitive,resultset.concur_updatable);pstmt.setstring(1, factoryname);rs = pstmt.executequery();while(rs.next()productinfopo oneproductinfopo=new productinfopo();oneproductinfopo.setproductname(rs.getstring("prod

12、uctname");oneproductinfopo.setfactoryname(rs.getstring("factoryname");oneproductinfopo.setproductkind(rs.getint("productkind");oneproductinfopo.setproducedate(rs.getstring("producedate");oneproductinfopo.setsaleprice(rs.getfloat("saleprice");oneproductinf

13、opo.setproductimage(rs.getstring("productimage");allproductinfo.add(oneproductinfopo);catch (sqlexception e)system.out.println(e.getmessage();finallytry con.close(); catch (sqlexception e) e.printstacktrace(); /可以及時關閉數(shù)據(jù)庫連接,數(shù)據(jù)庫連接沒有長期占用return allproductinfo;2、在xml配置文件中添加datasource和dao服務組件等的定

14、義<?xml version="1.0" encoding="utf-8"?><!doctype beans public "-/spring/dtd bean/en" "/dtd/spring-beans.dtd"> <beans> <bean id="productinfoactionbean" singleton="false" class="com.px198

15、7.sshwebshop.action.productinfomanage" > <property name="oneproductinfoservicebean"> <ref bean="productinfodaoservicebean" /> </property> </bean><bean id="productinfodaoservicebean" class="com.px1987.sshwebshop.service.imple.produ

16、ctinfodaoserviceimple" ><property name="datasource"><ref bean="datasourcetarget"/></property> </bean> <bean id="datasourcetarget" class="mons.dbcp.basicdatasource"> <property name="driverclassname"> <val

17、ue>com.mysql.jdbc.driver</value> </property> <property name="url"> <value>jdbc:mysql:/localhost:3306/webcrm</value> </property> <property name="username"> <value>root</value> </property> <property name="passwo

18、rd"> <value>root</value> </property> </bean> </beans>3、在項目中添加與dbcp有關的系統(tǒng)庫文件4、在項目中添加mysql的jdbc驅動程序5、在數(shù)據(jù)庫表中建立名稱為productinfo的數(shù)據(jù)庫表(1)創(chuàng)建productinfo的數(shù)據(jù)庫表相關的sql語句create table productinfo ( id varchar(255) not null, productname varchar(255) default null, factoryname varc

19、har(255) default null, productkind tinyint(4) default null, producedate varchar(255) default null, saleprice float default null, productimage varchar(255) default null, primary key (id) engine=innodb default charset=utf8;注意:數(shù)據(jù)庫表的字符集為utf-8類型的字符集。(2)表結構(3)在數(shù)據(jù)庫表中添加測試數(shù)據(jù)insert into productinfo values (&#

20、39;1', 'hp筆記本800', '美國hp公司', '1', '2010-8-30', '5000.5', '/images/hpcompute1.jpg');insert into productinfo values ('2', 'hp筆記本600', '美國hp公司', '1', '2010-6-30', '5100.5', '/images/hpcompute2.jpg

21、9;);insert into productinfo values ('3', 'hp筆記本700', '美國hp公司', '1', '2010-7-30', '5050.5', '/images/hpcompute3.jpg');insert into productinfo values ('4', 'hp筆記本500', '美國hp公司', '1', '2010-5-30', '5210.

22、5', '/images/hpcompute1.jpg');6、再測試本示例的相關測試頁面(1)啟動查詢表單頁面(2)在查詢表單中輸入相關的查詢參數(shù)將出現(xiàn)下面的查詢結果與前面的數(shù)據(jù)庫表中給的測試數(shù)據(jù)完全保持一致。1.1.3 在項目中添加頁面模板以美化各個頁面1、 在項目中添加下面的內(nèi)容2、在頁面中包含頁頭和頁尾燈文件<% include file ="/commonpage/pagehead.jsp"%><% page iselignored="false" pageencoding="utf-8&qu

23、ot;%><!doctype html public "-/w3c/dtd html 4.01 transitional/en"><html> <head> <title>這是產(chǎn)品信息查詢頁面</title> </head> <body> <center> <h2>下面為同步查詢的表單</h2><form action="$pagecontext.request.contextpath/productinfomanage!queryp

24、roductinfo.action" method="post" name="queryproductinfoform"> 請輸入產(chǎn)品的廠家名稱:<input type="text" name="factoryname"/> <input type="submit" name="submitbutton" value="開始查詢"/> </form></center> </body>

25、;</html><% include file ="/commonpage/pagehead.jsp"%><% page iselignored="false" pageencoding="utf-8"%><% taglib uri=" prefix="c" %><!doctype html public "-/w3c/dtd html 4.01 transitional/en"><html> <head&g

26、t; <title>這是產(chǎn)品信息查詢的結果頁面</title> </head> <body> <center> <table width="800" border="1" align="center" id="productinfotable" style="display:inline" bgcolor="#f0f8ff" bordercolorlight="#4da6ff" border

27、colordark="#ecf5ff"><thead> <tr> <td width="149"><div align="center">名稱</div></td> <td width="104"><div align="center">廠家</div></td> <td width="62"><div align="cen

28、ter">分類</div></td> <td width="134"><div align="center">時間</div></td> <td width="87"><div align="center">價格</div></td> <td width="80"><div align="center">照片</

29、div></td> <td width="64"><div align="center">修改</div></td> <td width="68"><div align="center">刪除</div></td> </tr> </thead> <tbody id="productinfoitems"> <c:foreach items =&

30、quot;$allproductinfo" var ="oneproductinfopo"> <tr> <td width="149"> $oneproductinfopo.productname </td> <td width="104"> $oneproductinfopo.factoryname </td> <td width="62"> <c:choose> <c:when test="$on

31、eproductinfopo.productkind = 1">筆記本</c:when> <c:when test="$oneproductinfopo.productkind = 2">臺式機</c:when> <c:when test="$oneproductinfopo.productkind = 3">智能手機</c:when> </c:choose> </td> <td width="134">$oneproduc

32、tinfopo.producedate</td> <td width="87">$oneproductinfopo.saleprice</td> <td width="80"> <img src="$pagecontext.request.contextpath$oneproductinfopo.productimage"> </td> <td width="64"> <div align="center"

33、> <a href="#">修改</a> </div> </td> <td width="68"><div align="center"><a href="#">刪除</a></div></td> </tr> </c:foreach> </tbody> </table> </center> </body></html><% include file ="/commonpage/authorinfo.jsp"%>3、再測試后將能夠看到下面的模板1.1.4 為本示例項目提供“模糊”查詢的功能1、在sql語句如何實現(xiàn)“模糊”查詢like %?%、 like %?、 like ?%2、修改數(shù)據(jù)訪問方法public arraylist doquesyproductinfo(string factoryname) arraylist allproductinfo=new arraylist();results

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論