综合性实验报告模版.docx

上传人:b****6 文档编号:3728466 上传时间:2022-11-24 格式:DOCX 页数:23 大小:705.62KB
下载 相关 举报
综合性实验报告模版.docx_第1页
第1页 / 共23页
综合性实验报告模版.docx_第2页
第2页 / 共23页
综合性实验报告模版.docx_第3页
第3页 / 共23页
综合性实验报告模版.docx_第4页
第4页 / 共23页
综合性实验报告模版.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

综合性实验报告模版.docx

《综合性实验报告模版.docx》由会员分享,可在线阅读,更多相关《综合性实验报告模版.docx(23页珍藏版)》请在冰豆网上搜索。

综合性实验报告模版.docx

综合性实验报告模版

软件学院综合性实验报告

专业:

JAVA年级/班级:

09计算机1班2010—2011学年第二学期

课程名称

JavaEE程序设计

指导教师

周运

姓名

李金振

学号

0928524068

实验地点

过街楼机房

实验时间

5月20、27、6月3、10、17日

上午1-2节

项目名称

用SSH框架开发网上书店

实验类型

综合性

一、实验目的

1.熟悉并掌握spring框架。

2.熟悉struts框架,了解struts2的工作机制及工作流程。

3.掌握hibernate语言的使用,能够实现对数据库的增﹑删﹑查﹑改。

4.熟悉开发流程,能够开发网上书店。

二、实验仪器或设备

1.计算机一台

2.开发软件MyEclipse,和数据库软件MySQL。

三、总体设计(设计原理、设计方案及流程等)

1.创建网上书店的数据库。

2.创建web工程。

3.加载Spring框架,以及所需的jar包,在Spring中创建相应的java类,构造bean对象,并调用bean对象。

4.进行数据库的链接。

5.加载hibernate框架,对数据进行持久化。

6.对数据库中对应的表进行hibernate逆向工程,以生成与之对应的java类。

7.加载struts框架及所需要的jar包。

8.对网上书店进行部署应用程序,启动测试。

四、实验步骤(包括主要步骤、代码分析等)

1.在MySQL中创建bookstore.sql(代码如下:

Createdatabasebookstore;

Usebookstore;

createtablebook

bookidintauto_incrementnotnull,

catalogidint,

booknamevarchar(20)notnull,

priceintnotnull,

picturevarchar(30)notnull,

primarykey(bookid)

);

createtablecatalog

catalogidintauto_incrementnotnull,

catalognamevarchar(20)notnull,

primarykey(catalogid)

);

createtableorderitem

orderitemidintauto_incrementnotnull,

orderidint,

bookidint,

quantityintnotnull,

primarykey(orderitemid)

);

createtableorders

orderidintauto_incrementnotnull,

useridint,

orderdatetimestampnotnull,

primarykey(orderid)

);

createtableuser

useridintauto_incrementnotnull,

usernamevarchar(20)notnull,

passwordvarchar(20)notnull,

sexvarchar(4),

ageint,

primarykey(userid)

);

altertablebookaddconstraintFK_Relationship_3foreignkey(catalogid)

referencescatalog(catalogid)ondeleterestrictonupdaterestrict;

altertableorderitemaddconstraintFK_Relationship_2foreignkey(orderid)

referencesorders(orderid)ondeleterestrictonupdaterestrict;

altertableorderitemaddconstraintFK_Relationship_4foreignkey(bookid)

referencesbook(bookid)ondeleterestrictonupdaterestrict;

altertableordersaddconstraintFK_Relationship_1foreignkey(userid)

referencesuser(userid)ondeleterestrictonupdaterestrict;

2.在MyEclipse中创建webProject,命名为bookstore。

3.加载Spring框架,添加用户自定义包hibernate和配置文件applicationContext.xml.

4.在MyEclipseDatabaseExplorer中创建数据库的链接。

5.加载hibernate框架。

点击next

6.在MyEclipseDatabaseExplorer中选中所创建的表,进行hibernate逆向工程,生成与数据库表对应的java对象和映射文件。

7.修改web.xml,代码如下:

xmlversion="1.0"encoding="UTF-8"?

>

xmlns="

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xsi:

schemaLocation="

index.jsp

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

struts2

/*

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

/WEB-INF/applicationContext.xml

8.加载struts框架,并加载所需要的jar包。

9.创建DAO,BaseDAO.java,IBookDAO.java,ICatalogDAO.java,IUserDAO.java

BaseDAO.java代码如下:

packageorg.apex.bookstore.dao;

importorg.hibernate.SessionFactory;

importorg.hibernate.classic.Session;

publicclassBaseDAO{

privateSessionFactorysessionFactory;

publicSessionFactorygetSessionFactory(){

returnsessionFactory;

}

publicvoidsetSessionFactory(SessionFactorysessionFactory){

this.sessionFactory=sessionFactory;

}

publicSessiongetSession(){

Sessionsession=sessionFactory.openSession();

returnsession;

}

}

IBookDAO.java代码如下:

packageorg.apex.bookstore.dao;

importjava.util.List;

importorg.apex.bookstore.vo.Book;

publicinterfaceIBookDAO{

publicListgetBookByCatalogid(Integercatalogid);

publicListgetBookByCatalogidPaging(Integercatalogid,intcurrentPage,intpageSize);

publicintgetTotalByCatalog(Integercatalogid);

publicBookgetBookById(Integerbookid);

publicListgetRequiredBookByHql(Stringhql);

publicListgetNewBook();

}

ICatalogDAO.java代码如下:

packageorg.apex.bookstore.dao;

importjava.util.List;

publicinterfaceICatalogDAO{

publicListgetAllCatalogs();

}

IUserDAO.java代码如下:

packageorg.apex.bookstore.dao;

importorg.apex.bookstore.vo.User;

publicinterfaceIUserDAO{

publicvoidsaveUser(Useruser);

publicUservalidateUser(Stringusername,Stringpassword);

publicbooleanexitUser(Stringusername);

}

10.创建service,IBookService.java,ICatalogService.java,IUserService.java

IBookService.java代码如下:

packageorg.apex.bookstore.service;

importjava.util.List;

importorg.apex.bookstore.vo.Book;

publicinterfaceIBookService{

publicListgetBookByCatalogid(Integercatalogid);

publicListgetBookByCatalogidPaging(Integercatalogid,intcurrentPage,intpageSize);

publicintgetTotalByCatalog(Integercatalogid);

publicBookgetBookById(Integerbookid);

publicListgetRequiredBookByHql(Stringhql);

publicListgetNewBook();

}

ICatalogService.java代码如下:

packageorg.apex.bookstore.service;

importjava.util.List;

publicinterfaceICatalogService{

publicListgetAllCatalogs();

}

IUserService.java代码如下:

packageorg.apex.bookstore.service;

importorg.apex.bookstore.vo.User;

 

publicinterfaceIUserService{

publicvoidsaveUser(Useruser);

publicUservalidateUser(Stringusername,Stringpassword);

publicbooleanexitUser(Stringusername);

}

11.创建action,包括BookAction.java和UserAction.java

BookAction.java代码如下:

packageorg.apex.bookstore.action;

importjava.util.List;

importjava.util.Map;

importorg.apex.bookstore.service.IBookService;

importorg.apex.bookstore.service.ICatalogService;

importorg.apex.bookstore.util.Pager;

importcom.opensymphony.xwork2.ActionContext;

importcom.opensymphony.xwork2.ActionSupport;

publicclassBookActionextendsActionSupport{

protectedICatalogServicecatalogService;

protectedIBookServicebookService;

protectedIntegercatalogid;

privateIntegercurrentPage=1;

privateStringbookname;

privateintminPrice;

privateintmaxPrice;

publicIntegergetCatalogid(){

returncatalogid;

}

publicvoidsetCatalogid(Integercatalogid){

this.catalogid=catalogid;

}

publicICatalogServicegetCatalogService(){

returncatalogService;

}

publicvoidsetCatalogService(ICatalogServicecatalogService){

this.catalogService=catalogService;

}

publicStringbrowseCatalog()throwsException{

Listcatalogs=catalogService.getAllCatalogs();

Maprequest=(Map)ActionContext.getContext().get("request");

request.put("catalogs",catalogs);

returnSUCCESS;

}

publicStringbrowseBookPaging()throwsException{

inttotalSize=bookService.getTotalByCatalog(catalogid);

Pagerpager=newPager(currentPage,totalSize);

//Listbooks=bookService.getBookByCatalogid(catalogid);

Listbooks=bookService.getBookByCatalogidPaging(catalogid,currentPage,pager.getPageSize());

Maprequest=(Map)ActionContext.getContext().get("request");

request.put("books",books);

request.put("pager",pager);

//购物车要返回时,需要记住返回的地址

Mapsession=ActionContext.getContext().getSession();

request.put("catalogid",catalogid);

returnSUCCESS;

}

publicStringbrowseBook()throwsException{

Listbooks=bookService.getBookByCatalogid(catalogid);

Maprequest=(Map)ActionContext.getContext().get("request");

request.put("books",books);

returnSUCCESS;

}

publicStringsearchBook()throwsException{

StringBufferhql=newStringBuffer("fromBookb");

if(bookname!

=null&&bookname.length()!

=0)

hql.append("whereb.booknamelike'%"+bookname+"%'");

//if(minPrice!

=0&&maxPrice!

=0)

//hql.append("andb.price>"+minPrice+"andb.price<"+maxPrice);

Listbooks=bookService.getRequiredBookByHql(hql.toString());

Maprequest=(Map)ActionContext.getContext().get("request");

System.out.println(hql);

System.out.println(bookname);

request.put("books",books);

returnSUCCESS;

}

publicStringnewBook()throwsException{

Listbooks=bookService.getNewBook();

Maprequest=(Map)ActionContext.getContext().get("request");

request.put("books",books);

returnSUCCESS;

}

publicIBookServicegetBookService(){

returnbookService;

}

publicvoidsetBookService(IBookServicebookService){

this.bookService=bookService;

}

publicIntegergetCurrentPage(){

returncurrentPage;

}

publicvoidsetCurrentPage(IntegercurrentPage){

this.currentPage=currentPage;

}

publicStringgetBookname(){

returnbookname;

}

publicvoidsetBookname(Stringbookname){

this.bookname=bookname;

}

}

UserAction.java代码如下:

packageorg.apex.bookstore.action;

importjava.util.Map;

importorg.apex.bookstore.service.IUserService;

importorg.apex.bookstore.service.impl.UserService;

importorg.apex.bookstore.vo.User;

importcom.opensymphony.xwork2.ActionContext;

importcom.opensymphony.xwork2.ActionSupport;

publicclassUserActionextendsActionSupport{

protectedStringusername;

protectedStringpassword;

protectedStringsex;

protectedintage;

protectedUseruser;

protectedIUserServiceuserService;

publicUsergetUser(){

returnthis.user;

}

publicvoidsetUser(Useruser){

this.user=user;

}

publicvoidsetUserService(IUserServiceuserService){

this.userService=userService;

}

publicIUserServicegetUserService(){

returnthis.userService;

}

publicStringexecute()throwsException{

Useru=userService.validateUser(user.getUsername(),user.getPassword());

if(u!

=null){

Mapsessio

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1