淮海工学院计算机工程学院实验报告书课程名J2EE环境与程序设计题目:实验七实现简单的图书在线销售系统1班级:软件131学号:2013122870姓名:王裕一、实验目的掌握Spring框架的基本使用方法,能够完成Java对象及对象之间的依赖注入定义,实现对象与对象间控制反转。掌握使用Spring将Struts、Spring、Hibernate三个框架在WEB应用中的集成。掌握图书在线销售系统主要功能模块的实现思路与方法。二、实验内容1、实现首页中的新书列表功能。2、实现将图书添加到购物车功能。3、实现购物车中图书名称、价格、数量,总价的显示功能。4.注册用户,并且登陆三、实验方法和步骤准备:安装Mysql数据库服务器。执行bookstore.sql.txt中的SQL命令,创建项目包括的数据表。----数据库:`bookstore`--createdatabasebookstore;usebookstore;--------------------------------------------------------------表的结构`book`--CREATETABLE`book`(`bookid`int(11)NOTNULLauto_increment,`catalogid`int(11)defaultNULL,`bookname`varchar(20)NOTNULL,`price`int(11)NOTNULL,`picture`varchar(30)NOTNULL,`recommend`int(11)NOTNULL,PRIMARYKEY(`bookid`),KEY`FK_Relationship_3`(`catalogid`))ENGINE=InnoDBDEFAULTCHARSET=utf8AUTO_INCREMENT=15;----导出表中的数据`book`--INSERTINTO`book`(`bookid`,`catalogid`,`bookname`,`price`,`picture`,`recommend`)VALUES(1,1,'书1',11,'a19.jpg',0),(2,2,'书2',22,'a15.jpg',1),(3,2,'书3',33,'a15.jpg',1),(5,2,'书5',55,'a15.jpg',1),(6,2,'书6',66,'a15.jpg',1),(7,2,'书7',77,'a15.jpg',1),(8,2,'书8',88,'a15.jpg',1),(9,2,'书9',99,'a15.jpg',1),(10,2,'书10',10,'a15.jpg',1),(11,2,'书11',11,'a15.jpg',1),(12,2,'书12',12,'a15.jpg',1),(13,2,'书13',13,'a15.jpg',1),(14,2,'书14',14,'a15.jpg',1);--------------------------------------------------------------表的结构`catalog`--CREATETABLE`catalog`(`catalogid`int(11)NOTNULLauto_increment,`catalogname`varchar(20)NOTNULL,PRIMARYKEY(`catalogid`))ENGINE=InnoDBDEFAULTCHARSET=utf8AUTO_INCREMENT=3;----导出表中的数据`catalog`--INSERTINTO`catalog`(`catalogid`,`catalogname`)VALUES(1,'类别1'),(2,'类别2');--------------------------------------------------------------表的结构`orderitem`--CREATETABLE`orderitem`(`orderitemid`int(11)NOTNULLauto_increment,`orderid`int(11)defaultNULL,`bookid`int(11)defaultNULL,`quantity`int(11)NOTNULL,PRIMARYKEY(`orderitemid`),KEY`FK_Relationship_2`(`orderid`),KEY`FK_Relationship_4`(`bookid`))ENGINE=InnoDBDEFAULTCHARSET=utf8AUTO_INCREMENT=1;----导出表中的数据`orderitem`----------------------------------------------------------------表的结构`orders`--CREATETABLE`orders`(`orderid`int(11)NOTNULLauto_increment,`userid`int(11)defaultNULL,`orderdate`timestampNOTNULLdefaultCURRENT_TIMESTAMPonupdateCURRENT_TIMESTAMP,PRIMARYKEY(`orderid`),KEY`FK_Relationship_1`(`userid`))ENGINE=InnoDBDEFAULTCHARSET=utf8AUTO_INCREMENT=1;----导出表中的数据`orders`----------------------------------------------------------------表的结构`user`--CREATETABLE`user`(`userid`int(11)NOTNULLauto_increment,`username`varchar(20)NOTNULL,`password`varchar(20)NOTNULL,`sex`varchar(4)defaultNULL,`age`int(11)defaultNULL,PRIMARYKEY(`userid`))ENGINE=InnoDBDEFAULTCHARSET=utf8AUTO_INCREMENT=2;----导出表中的数据`user`--INSERTINTO`user`(`userid`,`username`,`password`,`sex`,`age`)VALUES(1,'admin','admin',NULL,NULL),第一步:实现数据层的对象关系映射。第二步:实现DAO、Service、Action三层处理代码。第三步:通过applictionContext.xml完成Bean配置。第四步:实现视图。1、编写可保存图书信息的可持久化对象:org/apex/bookstore/vo/Book.javapackageorg.apex.bookstore.vo;importjava.util.HashSet;importjava.util.Set;/***Bookentity.**@authorMyEclipsePersistenceTools*/publicclassBookimplementsjava.io.Serializable{//FieldsprivateIntegerbookid;privateCatalogcatalog;privateStringbookname;privateIntegerprice;privateStringpicture;//Constructors/**defaultconstructor*/publicBook(){}/**minimalconstructor*/publicBook(Stringbookname,Integerprice,Stringpicture){this.bookname=bookname;this.price=price;this.picture=picture;}/**fullconstructor*/publicBook(Catalogcatalog,Stringbookname,Integerprice,Stringpicture){this.catalog=catalog;this.bookname=bookname;this.price=price;this.picture=picture;}//PropertyaccessorspublicIntegergetBookid(){returnthis.bookid;}publicvoidsetBookid(Integerbookid){this.bookid=bookid;}publicCataloggetCatalog(){returnthis.catalog;}publicvoidsetCatalog(Catalogcatalog){this.catalog=catalog;}publicStringgetBookname(){returnthis.bookname;}publicvoidsetBookname(Stringbookname){this.bookname=bookname;}publicIntegergetPrice(){returnthis.price;}publicvoidsetPrice(Integerprice){this.price=price;}publicStringgetPicture(){returnthis.picture;}publicvoidsetPicture(Stringpicture){this.picture=picture;}}2、编写Hibernate映射文件以实现ORM:org/apex/bookstore/vo/Book.hbm.xml?xmlversion=1.0encoding=utf-8?!DOCTYPEhibernate-mappingPUBLIC-//Hibernate/HibernateMappingDTD3.0//EN!--MappingfileautogeneratedbyMyEclipsePersistenceTools--hibernate-mappingclassname=org.apex.bookstore.vo.Booktable=bookidname=bookidtype=java.lang.Integercolumnname=bookid/generatorclass=native//idmany-to-onename=catalogclass=org.apex.bookstore.vo.Catalogfetch=selectlazy=falsecolumnname=catalogid//many-to-onepropertyname=booknametype=java.lang.Stringcolumnname=booknamelength=20not-null=true//propertypropertyname=pricetype=java.lang.Integercolumnname=pricenot-null=true//propertypropertyname=picturetype=java.lang.Stringcolumnname=picturelength=30not-null=true//property/class/hibernate-mapping3、在Spring配置文件applicationContext.xml中的sessionFactoryBean配置中合适的位置添加映射文件声明:value