版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料1.1 j2ee课程设计教学项目基于struts2+spring +hibernate(ssh)三大框架相互整合技术实现的数码产品管理系统的实现实例(第4部分)1.1.1 修改产品信息的功能实现1、实现数据修改的基本思路(1)首先查询出需要修改的数据(2)用户选中需要修改的数据,系统将显示输出待修改的原始数据(3)用户在修改表单中根据自己的要求,修改其中的相关数据,并提交修改的结果(4)系统后台获得修改后的所有结果,实现真正的修改;系统再次查询修改后的结果数据,并显示输出2、修改po增加id成员属性public string getid(
2、) return id;public void setid(string id) this.id = id;private string id;3、修改数据查询方法,获得每条记录的idwhile(rs.next()productinfopo oneproductinfopo=new productinfopo();oneproductinfopo.setid(rs.getstring(id);oneproductinfopo.setproductname(rs.getstring(productname);oneproductinfopo.setfactoryname(rs.getstring
3、(factoryname);oneproductinfopo.setproductkind(rs.getint(productkind);oneproductinfopo.setproducedate(rs.getstring(producedate);oneproductinfopo.setsaleprice(rs.getfloat(saleprice);oneproductinfopo.setproductimage(rs.getstring(productimage);allproductinfo.add(oneproductinfopo);4、在jsp页面中设计“修改”功能的超链接修改
4、5、在数据访问方法中增加一个方法public productinfopo doquesyproductinfobyid(string productid)productinfopo oneproductinfopo=null;resultset rs=null;trycon = datasource.getconnection();catch (sqlexception ex)system.out.println(ex.getmessage();string select_sqlstatement=select * from productinfo where id=?;try try jav
5、a.sql.preparedstatement pstmt = con.preparestatement(select_sqlstatement,resultset.type_scroll_sensitive,resultset.concur_updatable);pstmt.setstring(1, productid);rs = pstmt.executequery();while(rs.next()oneproductinfopo=new productinfopo();oneproductinfopo.setid(rs.getstring(id);oneproductinfopo.se
6、tproductname(rs.getstring(productname);oneproductinfopo.setfactoryname(rs.getstring(factoryname);oneproductinfopo.setproductkind(rs.getint(productkind);oneproductinfopo.setproducedate(rs.getstring(producedate);oneproductinfopo.setsaleprice(rs.getfloat(saleprice);oneproductinfopo.setproductimage(rs.g
7、etstring(productimage);catch (sqlexception e)system.out.println(e.getmessage();finallytry con.close(); catch (sqlexception e) e.printstacktrace(); return oneproductinfopo;6、编程action类中的“修改”的功能方法private string id=null;public string getid() return id;public void setid(string id) this.id = id;public str
8、ing updateproductinfo()productinfopo returnproductinfopo =productinfodaoserviceimple.doquesyproductinfobyid(id);httpservletrequest request =servletactioncontext.getrequest();request.setattribute(returnproductinfopo, returnproductinfopo);return gotoshowupdateform;7、在struts.xml文件中增加一个结果的定义 /productman
9、age/showproductinfo.jsp /productmanage/showupdateform.jsp 8、在项目中再添加一个显示修改数据的表单页面(1)页面的文件名称为showupdateform.jsp(2)设计修改的表单 这是修改产品信息表单页面 下面为待修改的原始数据 厂家名称: 产品名称: 产品价格: 产品分类: 笔记本 台式机 智能手机 笔记本 台式机 智能手机 笔记本 台式机 智能手机 出厂日期: 产品图片: hpcompute1 hpcompute2 hpcompute3 hpcompute1 hpcompute2 hpcompute3 hpcompute1 hpc
10、ompute2 hpcompute3 9、测试本示例目前的功能实现效果10、在项目中提供一个表单对象类package com.px1987.sshwebshop;public class productinfoactionform public productinfoactionform() public string getproductname() return productname;public void setproductname(string productname) ductname = productname;public string getfactoryn
11、ame() return factoryname;public void setfactoryname(string factoryname) this.factoryname = factoryname;public int getproductkind() return productkind;public void setproductkind(int productkind) ductkind = productkind;public string getproducedate() return producedate;public void setproducedat
12、e(string producedate) ducedate = producedate;public float getsaleprice() return saleprice;public void setsaleprice(float saleprice) this.saleprice = saleprice;public string getproductimage() return productimage;public void setproductimage(string productimage) ductimage = productimage
13、;public string getid() return id;public void setid(string id) this.id = id;private string productname;private string factoryname;private int productkind;private string producedate;private float saleprice;private string productimage;private string id;11、在数据访问类中添加修改方法public boolean doupdateproductinfo
14、(productinfopo updatedproductinfo)int returnresult =0;trycon = datasource.getconnection();catch (sqlexception ex)system.out.println(ex.getmessage();string update_sqlstatement=update productinfo set productname=?,factoryname=?,productkind=?,producedate=?,saleprice=?,productimage=? where id=?;try try
15、java.sql.preparedstatement pstmt = con.preparestatement(update_sqlstatement);pstmt.setstring(1, updatedproductinfo.getproductname();pstmt.setstring(2, updatedproductinfo.getfactoryname();pstmt.setint(3, updatedproductinfo.getproductkind();pstmt.setstring(4, updatedproductinfo.getproducedate();pstmt.
16、setfloat(5, updatedproductinfo.getsaleprice();pstmt.setstring(6, updatedproductinfo.getproductimage();pstmt.setstring(7, updatedproductinfo.getid();returnresult = pstmt.executeupdate();catch (sqlexception e)system.out.println(e.getmessage();finallytry con.close(); catch (sqlexception e) e.printstack
17、trace(); if(returnresult =0)return false;elsereturn true;12、编程action类中的updateproductform方法以响应修改表单的请求(1)将action类从字段驱动的action改变为模型驱动的action(2)updateproductform方法的代码public string updateproductform()/* * 将表单对象中的各个数据转存到po实体类对象中 */productinfopo updatedproductinfo=new productinfopo();updatedproductinfo.set
18、factoryname(oneproductinfo.getfactoryname();updatedproductinfo.setid(oneproductinfo.getid();updatedproductinfo.setproducedate(oneproductinfo.getproducedate();updatedproductinfo.setproductimage(oneproductinfo.getproductimage();updatedproductinfo.setproductkind(oneproductinfo.getproductkind();updatedproductinfo.setproductname(oneproductinfo.getproductname();updatedproductinfo.setsaleprice(oneproductinfo.getsaleprice();boolean returnupdateresult
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024-2025学年度上海政法学院单招《物理》模拟试题附答案详解【基础题】
- 2024-2025学年度农村信用社招聘考试考试黑钻押题(夺分金卷)附答案详解
- 小学取暖安全责任制度
- 定点帮扶责任制度
- 安检处置员岗位责任制度
- 信访渠道畅通责任制度
- 建筑质量责任制度
- 农家乐责任制度
- 危险物品安保责任制度
- 信息质量责任制度
- 2025 澳大利亚的奶制品产业课件
- 江苏省2026届高三上学期高考模拟考试(二)英语试卷(含解析无听力音频有听力原文)
- 2025年武汉创新投资集团有限公司公开选聘投资专业人员笔试参考题库附带答案详解
- 文化展示设计案例分析
- (正式版)DB51∕T 5066-2018 《四川省居住建筑油烟气集中排放系统应用技术标准》
- 2026年温州永嘉县国有企业面向社会公开招聘工作人员12人考试参考试题及答案解析
- 医疗人员跨境培训体系
- 2026年及未来5年中国音乐行业市场发展数据监测及投资战略咨询报告
- 无废工厂建设实施方案
- 长度和时间的测量课件2025-2026学年人教版物理八年级上册
- 2026年保安员资格证理论知识考试题库
评论
0/150
提交评论