myeclipse框架搭建步骤.docx

上传人:b****5 文档编号:7722915 上传时间:2023-01-26 格式:DOCX 页数:27 大小:1.76MB
下载 相关 举报
myeclipse框架搭建步骤.docx_第1页
第1页 / 共27页
myeclipse框架搭建步骤.docx_第2页
第2页 / 共27页
myeclipse框架搭建步骤.docx_第3页
第3页 / 共27页
myeclipse框架搭建步骤.docx_第4页
第4页 / 共27页
myeclipse框架搭建步骤.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

myeclipse框架搭建步骤.docx

《myeclipse框架搭建步骤.docx》由会员分享,可在线阅读,更多相关《myeclipse框架搭建步骤.docx(27页珍藏版)》请在冰豆网上搜索。

myeclipse框架搭建步骤.docx

myeclipse框架搭建步骤

myeclipse框架搭建步骤

Myeclipsessh框架搭建步骤

1项目创建

1.1创建web项目

1.2添加jar包到lib目录下

由于直接使用myeclipse添加ssh特性导致jar包冲突,因此事先把jar包添加到创建的项目的webroot下的web-inf文件夹的lib目录下

生成applicationContext.xml配置文件,点击finish。

1.1打开applicationContext.xml文件,把常用的命名空间加入

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

>

//www.springframework.org/schema/beans"

xmlns:

xsi="http:

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

context="http:

//www.springframework.org/schema/context"

xmlns:

aop="http:

//www.springframework.org/schema/aop"xmlns:

tx="http:

//www.springframework.org/schema/tx"

xsi:

schemaLocation="http:

//www.springframework.org/schema/beans

http:

//www.springframework.org/schema/beans/spring-beans-3.0.xsd

http:

//www.springframework.org/schema/context

http:

//www.springframework.org/schema/context/spring-context-3.0.xsd

http:

//www.springframework.org/schema/aop

http:

//www.springframework.org/schema/aop/spring-aop-3.0.xsd

http:

//www.springframework.org/schema/tx

http:

//www.springframework.org/schema/tx/spring-tx-3.0.xsd">

1.2在web.xml中添加spring监听:

contextConfigLocation

/WEB-INF/classes/applicationContext*.xml

org.springframework.web.context.ContextLoaderListener

配置监听的目的:

ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。

2添加hibernate

2.1数据库连接驱动

如果没有需要的数据库连接驱动,需要在添加特性之前,添加数据库连接驱动

Window->openperspective->myeclipsedatabaseexplorer

目前没有我们需要的驱动,我们这里使用mysql。

下一步

点击finish.

创建完毕之后,打开连接

这样,在添加hibernate特性时就会出现数据库连接驱动选择项。

2.2添加hibernate特性

同样,也不添加library

选择springconfigurationfile,点击下一步

选择已经存在的spring配置文件,点击下一步。

在这个对话框,dbdriver中选择刚才已创建的myconn。

这里不用再拷贝驱动到buildpath。

因为已经把相关的jar包拷贝过去了。

下一步。

不用创建hibernatesessionfactory,点击finish。

2.3查看applicationContext.xml配置文件

增加的内容:

class="mons.dbcp.BasicDataSource">

value="com.mysql.jdbc.Driver">

mysql:

//localhost:

3306/hpdb">

class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

org.hibernate.dialect.MySQLDialect

这里既是applicationContext.xml中会自动把数据源dataSource,sessionFactory添加。

2.4反向映射

2.4.1创建pojp和hbm文件所在的包。

2.4.2打开databaseexplorer

2.4.3打开数据库连接

2.4.4选择要反向映射的表,右键选择hibernate反向工程

第一个选项是创建hbm.xml文件,必须的。

第二个选项是创建pojo,必须的,创建pojo,事先需要创建包,com.hp.po。

第三个选项是创建dao。

这里因为我们要自己做dao,因此不用创建dao了。

下一步选择生成策略,native。

identity

这里如果不修改类名,会根据相关的策略,生成类名。

例如TUser。

2.4.5生成后问题及解决方式

生成后:

方法:

在生成类的时候指定包名。

如果移动路径,需要修改内容:

applicationContext.xml:

./User.hbm.xml

com/hp/po/Log.hbm.xml

修改为:

com/hp/po/User.hbm.xml

com/hp/po/Log.hbm.xml

User.hbm.xml:

修改为:

hibernate.reveng.xml

hibernate.reveng.xml文件可以删掉了

3添加struts

3.1添加struts特性

因为已经添加了struts2的jar包,因此不用在添加。

点击finish。

完成后主要做了两个工作。

一个是生成struts.xml,空文件,没有实质内容

在web.xml中添加struts的过滤器:

struts2

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

struts2

/*

FilterDispatcher是struts2.0.x到2.1.2版本的核心过滤器。

StrutsPrepareAndExecuteFilter是自2.1.3开始就替代了FilterDispatcher的。

3.2纳入spring容器管理

--纳入spring容器管理-->

整合的时候需要此操作需要struts2-spring-plugin-xxx.jar

4常用配置添加

4.1在applicationContext.xml文件中

4.1.1常用配置

中添加

--设置Hibernate方言-->

org.hibernate.dialect.MySQLDialect

--是否打印sql-->

true

--格式化sql-->

true

--是否自动更新表-->

update

thread

--最大抓取深度,如果为0,则关闭默认的外连接抓取。

建议值为0-3-->

1

--用于生成有助于调试的注释信息,默认为关闭-->

true

4.1.2事务配置

--声明式事务配置-->

class="org.springframework.orm.hibernate3.HibernateTransactionManager">

--AOP切面声明事务管理-->

adviceid="txAdvice"transaction-manager="transactionManager">

attributes>

--支持当前事务,如果执行到save开头的任何方法时没有事务则开启一个事务-->

methodname="save*"propagation="REQUIRED"/>

--支持当前事务,如果执行到update开头的任何方法时没有事务则开启一个事务-->

methodname="update*"propagation="REQUIRED"/>

--支持当前事务,如果执行到add开头的任何方法时没有事务则开启一个事务-->

methodname="add*"propagation="REQUIRED"/>

--支持当前事务,如果执行到delete开头的任何方法时没有事务则开启一个事务-->

methodname="delete*"propagation="REQUIRED"/>

--支持当前事务,查询没有事务,就以非事务方式执行。

只读-->

methodname="get*"propagation="SUPPORTS"read-only="true"/>

--支持当前事务,查询没有事务,就以非事务方式执行。

只读-->

methodname="find*"propagation="SUPPORTS"read-only="true"/>

methodname="*"read-only="true"propagation="NOT_SUPPORTED"/>

attributes>

advice>

 

在struts.xml文件中添加:

--开发常量配置-->

--指定Struts2是否为开发模式,若为开发模式,程序运行错误时会得到更多的信息-->

--设置浏览器是否缓存静态页面,开发阶段:

false,上线:

true-->

--当struts.xml文件改动时,是否重新加载该文件,为提高开发效率,开发阶段是true-->

--指定默认编码规则,对于请求参数中含有中文的时候应该使用UTF-8-->

--默认的视图-->

--指定全局的国际化标签-->

--上传下载-->

--指定请求的后缀名,默认为action,若为多个的话,之间用逗号隔开-->

--将struts2的action交给Spring管理-->

--引入各模块业务的struts配置

-->

 

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

当前位置:首页 > 高等教育 > 其它

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

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