Rumah > Artikel > pangkalan data > OA项目1:环境搭建之数据库创建与环境添加
首注:本学习教程为 传智播客汤阳光 一 指定数据库:Mysql database:oa 建库语句:create database oa default character set utf8 二 指定ide开发工具:MyEclipse 项目名称:新建web工程,名字为:OA,并设置项目工程编码:utf-8 环境所用主要技术框架:JU
首注:本学习教程为传智播客汤阳光
一 指定数据库:Mysql
database:oa
建库语句:create database oa default character set utf8
二 指定ide开发工具:MyEclipse
项目名称:新建web工程,名字为:OA,并设置项目工程编码:utf-8
环境所用主要技术框架:JUnit4,Struts2.3.15.1,Hibernate3.6,Spring2.5.6,jQuery,……
三 添加框架环境:
1.添加JUnit环境:
右击项目名称 --> Build Path --> Add Libraries --> JUnit,点击next,选择版本为JUnit 4,点击finish。完成JUnit环境添加。
2.添加Struts2.3.15.1环境:
添加jar包:
事先到官网下载好对应版本的项目环境,解压后打开进入apps文件夹里,用好压工具打开struts2-blank.war,点击WEB-INF,
将lib下面的jar包全部复制到我们OA项目的lib下面。
添加配置文件:
用好压工具打开struts2-blank.war,点击WEB-INF,将src --> java下面的struts.xml拷贝到我们OA项目的src下面。然后将
struts.xml里的内容修改为如下内容:
<span> 1</span> <span></span><span>xml version="1.0" encoding="UTF-8" </span><span>?></span> <span> 2</span> <span><span>DOCTYPE struts PUBLIC </span><span> 3</span> <span> "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" </span><span> 4</span> <span> "http://struts.apache.org/dtds/struts-2.3.dtd"</span><span>></span> <span> 5</span> <span> 6</span> <span><span>struts</span><span>></span> <span> 7</span> <span> 8</span> <span><!--</span><span> 设置为开发者模式 </span><span>--></span> <span> 9</span> <span><span>constant </span><span>name</span><span>="struts.devMode"</span><span> value</span><span>="true"</span> <span>/></span> <span>10</span> <span><!--</span><span> 把扩展名设置为.action,如name里的内容记不住,请在core包里的default.properties里面找 </span><span>--></span> <span>11</span> <span><span>constant </span><span>name</span><span>="struts.action.extension"</span><span> value</span><span>="action"</span> <span>/></span> <span>12</span> <span><!--</span><span> 把主题设置为simple,如name里的内容记不住,请在core包里的default.properties里面找 </span><span>--></span> <span>13</span> <span><span>constant </span><span>name</span><span>="struts.ui.theme"</span><span> value</span><span>="simple"</span> <span>/></span> <span>14</span> <span>15</span> <span><span>package </span><span>name</span><span>="default"</span><span> namespace</span><span>="/"</span><span> extends</span><span>="struts-default"</span><span>></span> <span>16</span> <span>17</span> <span></span><span>package</span><span>></span> <span>18</span> <span>19</span> <span><!--</span><span> Add packages here </span><span>--></span> <span>20</span> <span>21</span> <span></span><span>struts</span><span>></span></span></span></span></span></span></span>
如果xml的代码不提示,在我们下载的项目包里面找,具体位置为:struts-2.3.15.1/src/core/src/main/resources/struts-2.3.dtd。
然后配置到myeclipse里面即可。
用好压工具打开struts2-blank.war,点击WEB-INF,将web.xml里面的以下内容拷贝到我们的web.xml里面:
<span> 1</span> <span><span>filter</span><span>></span> <span> 2</span> <span> 3</span> <span><span>filter-name</span><span>></span>struts2<span></span><span>filter-name</span><span>></span> <span> 4</span> <span> 5</span> <span><span>filter-class</span><span>></span>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter<span></span><span>filter-class</span><span>></span> <span> 6</span> <span> 7</span> <span></span><span>filter</span><span>></span> <span> 8</span> <span> 9</span> <span>10</span> <span>11</span> <span><span>filter-mapping</span><span>></span> <span>12</span> <span>13</span> <span><span>filter-name</span><span>></span>struts2<span></span><span>filter-name</span><span>></span> <span>14</span> <span>15</span> <span><span>url-pattern</span><span>></span>/*<span></span><span>url-pattern</span><span>></span> <span>16</span> <span>17</span> <span></span><span>filter-mapping</span><span>></span></span></span></span></span></span></span>
3.添加hibernate3.6的环境:
添加jar包:
1)添加核心包:hibernate3.jar
2)项目包里lib文件夹下面:required里面全部jar包,jpa文件夹里面全部jar包,optional文件夹里c3p0包。
3)mysql驱动包。
添加配置文件:
1)添加hibernate.cfg.xml,具体模板内容如下(在项目环境添加完成之后再做修改):
<span> 1</span> <span><span>DOCTYPE hibernate-configuration PUBLIC </span><span> 2</span> <span> "-//Hibernate/Hibernate Configuration DTD 3.0//EN" </span><span> 3</span> <span> "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"</span><span>></span> <span> 4</span> <span> 5</span> <span><span>hibernate-configuration</span><span>></span> <span> 6</span> <span><span>session-factory </span><span>name</span><span>="foo"</span><span>></span> <span> 7</span> <span><!--</span><span> 显示sql </span><span>--></span> <span> 8</span> <span><span>property </span><span>name</span><span>="show_sql"</span><span>></span>true<span></span><span>property</span><span>></span> <span> 9</span> <span>10</span> <span><span>property </span><span>name</span><span>="hbm2ddl.auto"</span><span>></span>update<span></span><span>property</span><span>></span> <span>11</span> <span><!--</span><span> mysql方言 </span><span>--></span> <span>12</span> <span><span>property </span><span>name</span><span>="dialect"</span><span>></span>org.hibernate.dialect.MySQL5Dialect<span></span><span>property</span><span>></span> <span>13</span> <span><!--</span><span> 数据库连接信息 </span><span>--></span> <span>14</span> <span><!--</span><span> 数据库驱动 </span><span>--></span> <span>15</span> <span><span>property </span><span>name</span><span>="connection.driver_class"</span><span>></span>com.mysql.jdbc.Driver<span></span><span>property</span><span>></span> <span>16</span> <span><span>property </span><span>name</span><span>="connection.url"</span><span>></span>jdbc:mysql:///oa<span></span><span>property</span><span>></span> <span>17</span> <span><span>property </span><span>name</span><span>="connection.username"</span><span>></span>root<span></span><span>property</span><span>></span> <span>18</span> <span><span>property </span><span>name</span><span>="connection.password"</span><span>></span>root<span></span><span>property</span><span>></span> <span>19</span> <span><!--</span><span> 导入映射文件 </span><span>20</span> <span> <mapping resource="org/hibernate/test/legacy/Simple.hbm.xml"/> </span><span>--></span> <span>21</span> <span></span><span>session-factory</span><span>></span> <span>22</span> <span></span><span>hibernate-configuration</span><span>></span></span></span></span></span></span></span></span></span></span></span>
2)添加XX.hbm.xml模板,内容如下(具体代码开发时添加修改):
<span>1</span> <span></span><span>xml version="1.0"</span><span>?></span> <span>2</span> <span><span>DOCTYPE hibernate-mapping PUBLIC </span><span>3</span> <span> "-//Hibernate/Hibernate Mapping DTD 3.0//EN" </span><span>4</span> <span> "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"</span><span>></span> <span>5</span> <span>6</span> <span><span>hibernate-mapping </span><span>package</span><span>="org.hibernate.test.typedmanytoone"</span><span>></span> <span>7</span> <span>8</span> <span></span><span>hibernate-mapping</span><span>></span></span></span>
4.添加Spring2.5.6开发环境:
添加jar包:
1)核心包:
spring.jar
2)依赖包:
spring2.5.6/lib/aspectj下面所有jar包
spring2.5.6/lib/lib/cglib下面的jar包
spring2.5.6/lib/jakarta-commons/commons-logging.jar(如已经添加就不需要了)
添加配置文件applicationConxt.xml,模板内容如下(具体内容在ssh整合时完善):
<span> 1</span> <span></span><span>xml version="1.0" encoding="UTF-8"</span><span>?></span> <span> 2</span> <span><!--</span> <span> 3</span> <span> - Middle tier application context definition for the image database. </span><span> 4</span> <span>--></span> <span> 5</span> <span><span>beans </span><span>xmlns</span><span>="http://www.springframework.org/schema/beans"</span> <span> 6</span> <span> xmlns:xsi</span><span>="http://www.w3.org/2001/XMLSchema-instance"</span> <span> 7</span> <span> xmlns:context</span><span>="http://www.springframework.org/schema/context"</span> <span> 8</span> <span> xmlns:tx</span><span>="http://www.springframework.org/schema/tx"</span> <span> 9</span> <span> xsi:schemaLocation</span><span>="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd </span><span>10</span> <span> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd </span><span>11</span> <span> http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"</span><span>></span> <span>12</span> <span>13</span> <span><!--</span><span> 自动扫描与装配bean </span><span>--></span> <span>14</span> <span><span>context:component-scan </span><span>base-package</span><span>="cn.clear.oa"</span><span>></span><span>context:component-scan</span><span>></span> <span>15</span> <span>16</span> <span>17</span> <span></span><span>beans</span><span>></span></span></span>