J2EE课程设计教学项目基于Struts2SpringHibernateSSH三大框架相互整合技术实现的数码产品管理系统的实现实例第3部分_第1页
J2EE课程设计教学项目基于Struts2SpringHibernateSSH三大框架相互整合技术实现的数码产品管理系统的实现实例第3部分_第2页
J2EE课程设计教学项目基于Struts2SpringHibernateSSH三大框架相互整合技术实现的数码产品管理系统的实现实例第3部分_第3页
J2EE课程设计教学项目基于Struts2SpringHibernateSSH三大框架相互整合技术实现的数码产品管理系统的实现实例第3部分_第4页
J2EE课程设计教学项目基于Struts2SpringHibernateSSH三大框架相互整合技术实现的数码产品管理系统的实现实例第3部分_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料1.1 j2ee课程设计教学项目基于struts2+spring +hibernate(ssh)三大框架相互整合技术实现的数码产品管理系统的实现实例(第3部分)1.1.1 将数据访问组件也由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方法,删除下面的对象创建的语句public string queryproductinfo () /oneproductinfoservicebean=new productinfodaoserviceimple();3、修改spring配置文件定义数据访问组件<?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、再测试本示例的相关测试页面查询的结果与前面的结果一样,只是不出现任何的错误。1.1.2 实现对数据库表中的真实数据进行访问操作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(); /可以及时关闭数据库连接,数据库连接没有长期占用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有关的系统库文件4、在项目中添加mysql的jdbc驱动程序5、在数据库表中建立名称为productinfo的数据库表(1)创建productinfo的数据库表相关的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;注意:数据库表的字符集为utf-8类型的字符集。(2)表结构(3)在数据库表中添加测试数据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)在查询表单中输入相关的查询参数将出现下面的查询结果与前面的数据库表中给的测试数据完全保持一致。1.1.3 在项目中添加页面模板以美化各个页面1、 在项目中添加下面的内容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>这是产品信息查询页面</title> </head> <body> <center> <h2>下面为同步查询的表单</h2><form action="$pagecontext.request.contextpath/productinfomanage!queryp

24、roductinfo.action" method="post" name="queryproductinfoform"> 请输入产品的厂家名称:<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>这是产品信息查询的结果页面</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语句如何实现“模糊”查询like %?%、 like %?、 like ?%2、修改数据访问方法public arraylist doquesyproductinfo(string factoryname) arraylist allproductinfo=new arraylist();results

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论