myeclipse框架搭建步骤文档格式.docx

上传人:b****5 文档编号:20848706 上传时间: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

xsi:

schemaLocation="

//www.springframework.org/schema/beans

http:

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

http:

//www.springframework.org/schema/context

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

//www.springframework.org/schema/aop

http:

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

//www.springframework.org/schema/tx

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

/beans>

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

<

context-param>

<

param-name>

contextConfigLocation<

/param-name>

param-value>

/WEB-INF/classes/applicationContext*.xml<

/param-value>

/context-param>

listener>

listener-class>

org.springframework.web.context.ContextLoaderListener<

/listener-class>

/listener>

配置监听的目的:

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配置文件

增加的内容:

beanid="

dataSource"

class="

mons.dbcp.BasicDataSource"

propertyname="

driverClassName"

value="

com.mysql.jdbc.Driver"

/property>

url"

value="

jdbc:

mysql:

//localhost:

3306/hpdb"

username"

root"

password"

/bean>

sessionFactory"

org.springframework.orm.hibernate3.LocalSessionFactoryBean"

<

refbean="

/>

hibernateProperties"

props>

<

propkey="

hibernate.dialect"

org.hibernate.dialect.MySQLDialect

/prop>

/props>

这里既是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:

list>

value>

./User.hbm.xml<

/value>

com/hp/po/Log.hbm.xml<

/list>

修改为:

com/hp/po/User.hbm.xml<

User.hbm.xml:

classname="

User"

table="

t_user"

catalog="

hpdb"

com.hp.po.User"

hibernate.reveng.xml

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

3添加struts

3.1添加struts特性

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

点击finish。

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

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

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

filter>

filter-name>

struts2<

/filter-name>

filter-class>

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

/filter-class>

/filter>

filter-mapping>

url-pattern>

/*<

/url-pattern>

/filter-mapping>

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

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

3.2纳入spring容器管理

!

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

constantname="

struts.objectFactory"

spring"

/constant>

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

4常用配置添加

4.1在applicationContext.xml文件中

4.1.1常用配置

在<

中添加

--设置Hibernate方言-->

org.hibernate.dialect.MySQLDialect<

--是否打印sql-->

hibernate.show_sql"

true<

--格式化sql-->

hibernate.format_sql"

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

hibernate.hbm2ddl.auto"

update<

hibernate.current_session_context_class"

thread<

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

建议值为0-3-->

hibernate.max_fetch_depth"

1<

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

hibernate.use_sql_comments"

4.1.2事务配置

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

transactionManager"

org.springframework.orm.hibernate3.HibernateTransactionManager"

reflocal="

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

tx:

adviceid="

txAdvice"

transaction-manager="

attributes>

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

methodname="

save*"

propagation="

REQUIRED"

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

update*"

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

add*"

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

delete*"

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

只读-->

get*"

SUPPORTS"

read-only="

true"

find*"

*"

NOT_SUPPORTED"

/tx:

advice>

 

在struts.xml文件中添加:

--开发常量配置-->

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

struts.devMode"

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

false,上线:

true-->

struts.serve.static.browserCache"

false"

/>

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

struts.configuration.xml.reload"

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

struts.i18n.encoding"

utf-8"

--默认的视图-->

struts.ui.theme"

simple"

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

struts.custom.i18n.resources"

global"

--上传下载-->

struts.multipart.maxSiz"

6000000"

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

struts.action.extension"

action,do"

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

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

includefile="

struts-user.xml"

/include>

-->

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

当前位置:首页 > 外语学习 > 法语学习

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

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