免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Spring2.5、Struts2、Ibatis開發(fā)框架搭建 技術(shù) 網(wǎng)街
一、框架下載
1.1   Struts2框架
Struts2框架發(fā)展于WebWork,現(xiàn)在捐獻給了Apache開源組織,最新版本的Struts2框架可以從位于Apache官方網(wǎng)站的Struts2項目中獲取,Struts2框架的項目主頁地址為:http://struts.apache.org/ ,下載頁面地址為: http://struts.apache.org/download.cgi
,打開下載地址以后自己選擇最新發(fā)布的版本即可,新手的話下載Full Distribution的版本,例如http://struts.apache.org/download.cgi#struts2014中的struts-2.0.14-full.zip。
為了讓struts2能夠支持json格式的返回數(shù)據(jù),還需要下載json插件,下載地址為
1.2   Spring2.5 框架
Spring框架的官方網(wǎng)站地址:http://www.springframework.org/,下載頁面為:http://www.springsource.org/download,打開下載頁面以后選擇Get the latest Spring releases here中的發(fā)行包去下載使用,注意Spring官方網(wǎng)站中包含的框架有很多,包括流程處理、安全、Web服務(wù)等很多種框架,我們需要下載的框架是Spring FrameWork 的某個版本,不是其它的那些框架。
1.3   Ibatis框架

iBATIS框架的主頁是http://ibatis.apache.org/,在打開的網(wǎng)站界面中選擇 選擇左邊的Get software中的for java連接,在打開的界面中選擇下載連接。

1.4   其它(數(shù)據(jù)庫緩沖池框架等)
如果需要使用Ms Sql Server數(shù)據(jù)庫的話,還需要在項目中加入jtds的JDBC驅(qū)動程序,下載地址http://jtds.sourceforge.net/,找到download連接,按提示信息下載即可。下載DBCP數(shù)據(jù)庫緩沖池框架,下載地址為http://commons.apache.org/dbcp/,下載最新版本即可,因為DBCP框架是apache開源軟件組織的眾多框架中的一部分,要讓DBCP工作的話,還需要common-pool框架,自行到apache官方網(wǎng)站下載。

 

二、向項目中加入Spring Struts iBATIS框架

2.1 準備工作

       將下載的三個框架分別解壓縮。

新建一個Web Project。

       2.2 向項目中加入Spring框架

Spring解壓縮以后spring-framework-2.5.6-with-dependencies\spring-framework-2.5.6\dist目錄中的spring.jar復制到Web項目的WEB-INF/lib目錄中。

復制spring-framework-2.5.6-with-dependencies\spring-framework-2.5.6\lib\log4j中的log4j相關(guān)的jar文件到項目中WEB-INF/lib目錄中。

打開WEB項目中的WEB-INF目錄中的web.xml文件,添加及結(jié)合項目實際情況配置以下內(nèi)容

    <!-- 以為是應用程序名稱 -->

       <display-name>JI</display-name>

       <!-- 以下是應用程序描述說明性文字 -->

       <description>Job Integration</description>

      

       <!-- 上下文參數(shù),用于log4j以及spring中使用 -->

       <context-param>

              <param-name>webAppRootKey</param-name>

              <param-value>ji.root</param-value>

       </context-param>

      

       <!-- 應用程序上下文參數(shù),指定log4j日志框架使用的配置參數(shù)文件位置 -->

       <context-param>

              <param-name>log4jConfigLocation</param-name>

              <param-value>/WEB-INF/log4j.properties</param-value>

       </context-param>

 

    <!-- 應用程序上下文參數(shù),指定spring配置文件位置 -->

       <context-param>

              <param-name>contextConfigLocation</param-name>

              <param-value>

 

在這里寫Spring參數(shù)配置文件的路徑

 

例如 /WEB-INF/spring/applicationContext.xml

 

</param-value>

       </context-param>

 

       <!-- 監(jiān)聽器,用于初始化log4j日志框架的 -->

       <listener>

              <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

       </listener>

       <!-- 監(jiān)聽器,用于初始化spring框架 -->

       <listener>

              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

       </listener>

2.3 向項目中添加Struts2框架

       打開解壓縮以后的Struts2框架目錄,找到\struts-版本-all\struts-版本\lib目錄,復制*.jar文件到WEB項目的WEB-INF/lib目錄中。

       復制jsonplugin-0.31.jar  到項目的WEB-INF/lib目錄中。

       打開WEB項目中的WEB-INF/web.xml文件,添加以下內(nèi)容:

       <!-- 過濾器,struts2使用的,用于銷毀某些不再使用的對象等-->

    <filter>

        <filter-name>struts-cleanup</filter-name>

        <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>

    </filter>

 

       <!--過濾器,struts2使用的 -->

    <filter>

        <filter-name>struts</filter-name>

        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

    </filter>

 

    <!-- 以下是struts2使用的用于清除或銷毀某些對象的過濾器,要保證在struts過濾器映射之前配置這一項 -->

    <filter-mapping>

        <filter-name>struts-cleanup</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

   

       <!-- struts2用于的過濾器映射 -->

    <filter-mapping>

        <filter-name>struts</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

 

找到項目的源程序目錄,一般在Eclipse開發(fā)工具中都是src目錄,添加以下幾個文件(注意大小寫),struts.properties,struts.xml,globalMessages.properties ,其中

struts.properties文件中的內(nèi)容為:

struts.custom.i18n.resources=globalMessages

struts.objectFactory=spring

struts.objectFactory.spring.autoWire=type

struts.ui.theme=simple

struts.locale =zh_CN

struts.i18n.encoding=UTF-8

struts.configuration.xml.reload=true

struts.multipart.parser=jakarta

struts.multipart.maxSize=10000000

struts.devMode=false

 

globalMessages.properties文件中的內(nèi)容為:

SMSPageTitle=\u5b89\u5fbd\u7701\u8840\u6db2\u4fe1\u606f\u77ed\u4fe1\u5e73\u53f0

login.error=\u60a8\u8f93\u5165\u7684\u7528\u6237\u540d\u6216\u5bc6\u7801\u9519\u8bef\uff01

userId.required=\u60a8\u7684\u7528\u6237\u540d\u4e0d\u80fd\u4e3a\u7a7a\uff01\uff01

passward.required=\u60a8\u7684\u5bc6\u7801\u4e0d\u80fd\u4e3a\u7a7a\uff01\uff01

datebase.error=\u6570\u636e\u5e93\u64cd\u4f5c\u9519\u8bef\uff01\uff01\uff01

validCode_error=\u9a8c\u8bc1\u7801\u9519\u8bef\uff01\uff01

retistSdk.error=\u6ce8\u518cSDK\u5931\u8d25\uff01\u8bf7\u68c0\u67e5\u5e8f\u5217\u53f7\u548c\u5bc6\u7801\uff01\uff01

retistSdk.success=\u8f6f\u4ef6SDK\u6ce8\u518c\u6210\u529f\uff01\uff01\uff01

logoutSdk.success=\u60a8\u5df2\u6210\u529f\u6ce8\u9500SDK\uff01\uff01

logoutSdk.error=\u6ce8\u9500SDK\u5931\u8d25\uff0c\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5\uff01\uff01\uff01

chargUp.error=\u5145\u503c\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u5361\u53f7\u548c\u5bc6\u7801\uff01\uff01

sdkNotReg=\u7cfb\u7edfSDK\u6ca1\u6709\u6ce8\u518c\uff01\uff01\uff01\uff01

struts.messages.error.uploading=\u6587\u4ef6\u65e0\u6cd5\u6b63\u5e38\u4e0a\u4f20

struts.messages.error.file.too.large=\u6587\u4ef6\u5927\u5c0f\u8d85\u8fc7\u6700\u5927\u5141\u8bb8\u503c

struts.messages.error.content.type.not.allowed=\u6587\u4ef6\u7c7b\u578b\u4e0d\u5728\u4e0a\u4f20\u6587\u4ef6\u5141\u8bb8\u7c7b\u578b\u4e2d

最后一個文件是struts.xml中的內(nèi)容,這個文件是struts的參數(shù)配置文件,參考配置內(nèi)容:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

       <constant name="struts.i18n.encoding" value="UTF-8"></constant>

       <package name="login" extends="struts-default">

              <action name="login" class="edu.xw.ji.action.LoginAction"

                     method="login">

                     <result name="success">/dev_test/login.jsp</result>

              </action>

       </package>

       <package name="ji_common" extends="json-default">

              <interceptors>

                     <interceptor-stack name="myDefaultStack">

                            <interceptor-ref name="defaultStack" />

                     </interceptor-stack>

              </interceptors>

              <default-interceptor-ref name="myDefaultStack"></default-interceptor-ref>

              <global-results>

                     <result name="error">/pages/errorMessage.jsp</result>

                     <result name="warn">/pages/warnMessage.jsp</result>

              </global-results>

       </package>

 

       <include file="edu/xw/ji/action/dict/struts2_dict.xml" />

       </struts>

注意上面的struts.xml配置文件中有兩個示例package,名稱為loginpackage是從struts-default包繼承下來的,不能夠?qū)崿F(xiàn)json格式的action返回,后面的ji_common是從json-default包繼承下來的,以后在項目中所有程序開發(fā)人員自己編寫的action中使用到json格式的返回結(jié)果時可以從ji_common包繼承下來。

       2.4 向項目中添加iBATIS框架

              找到解壓縮的iBATIS壓縮包中的ibatis-2.3.4.726\lib目錄,復制里面的.jar文件到項目中的WEB-INF/lib目錄中。

       2.5 添加數(shù)據(jù)庫緩沖池框架

              復制DBCP緩沖池框架中的commons-dbcp-x.x.x.jar文件到項目中WEB-INF/lib目錄中去,復制DBCP框架工作時需要使用的common-pool相關(guān)的jar文件到項目中的WEB-INF/lib目錄中去,DBCP在項目中是被配置到spring當中去使用,所以接下來的一系列工作都與spring的配置有關(guān)。

三、整合Spring2.5,Struts2,iBATIS,DBCP,Log4j

3.1 what’s the point?

       為什么要“整合”這些框架呢?在程序代碼中由程序員負責處理與控制一切不是很好嗎?要這么多的框架搭配在一起工作有什么好處呢?答案只有一個,“省事”,節(jié)省程序員開發(fā)程序的時間。

整合這些框架的關(guān)鍵一點就是Spring,Spring是所有這些框架在一起工作的粘合劑,整合的工作重心就是將web MVC框架、ORM框架、數(shù)據(jù)庫緩沖池框架、日志框架等全部交給Spring管理,由Spring調(diào)配使用這些框架綜合在一起工作。

       3.2 Spring如何讓Web項目加載?

              在第2.2小節(jié)中的配置參數(shù)中有一個listener是用來讓我們的web項目在啟動時就可以自動加載Spring框架及其參數(shù)配置文件的,即下面的這一行配置參數(shù)。

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

       </listener>

       3.3 Spring的參數(shù)配置文件如何被自動加載上?

              配置了Spring自動加載以后,在web項目的WEB-INF/web.xml中應該配置Spring參數(shù)文件的加載位置,即在2.2小節(jié)中需要配置的

   <!-- 應用程序上下文參數(shù),指定spring配置文件位置 -->

       <context-param>

              <param-name>contextConfigLocation</param-name>

              <param-value>/WEB-INF/spring/applicationContext.xml  /WEB-INF/spring/ibatis_dao.xml /WEB-INF/spring/struts_action.xml</param-value>

       </context-param>

<param-value>后面配置Spring參數(shù)文件的路徑,有多個Spring的參數(shù)配置文件存在時,各個參數(shù)文件之間用空格分隔開。

       3.4 如何讓Spring管理Struts2?

              要讓Spring管理Struts2action bean的創(chuàng)建等工作,需要在項目的src目錄中的struts.properties文件中指定

struts.objectFactory=spring

struts.objectFactory.spring.autoWire=type

       2.3 小節(jié)配置參數(shù)中包含的這兩行。

       3.5 如何讓Spring管理數(shù)據(jù)庫緩沖池?

              DBCP或者C3p0等數(shù)據(jù)庫緩沖池可以在Spring的參數(shù)配置文件當中去配置使用,例如在項目中配置DBCP數(shù)據(jù)庫緩沖池的話可以指定以下格式的參數(shù)配置:

 

       <bean id="dataSource"

              class="org.apache.commons.dbcp.BasicDataSource"

              destroy-method="close">

              <property name="driverClassName"

                     value="${jdbc.driverClassName}" />

              <property name="url" value="${jdbc.url}" />

              <property name="username" value="${jdbc.username}" />

              <property name="password" value="${jdbc.password}" />

              <property name="initialSize" value="4" />

              <property name="maxActive" value="20" />

              <property name="testWhileIdle" value="true" />

              <property name="validationQuery"

                     value="select count(0) from t_db_history where 1=2" />

              <property name="testOnBorrow" value="true" />

       </bean>

       上面各個參數(shù)值中有的使用的是$符號加{}的形式進行配置的,這種配置格式需要在Spring當中配置一個能夠加載.propertis文件的bean,如以下格式:

       <bean id="propertyConfigurer"

              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

              <property name="locations">

                     <list>

                            <value>WEB-INF/jdbc.properties</value>

                     </list>

              </property>

       </bean>

       上面配置參數(shù)中的list元素后面跟隨.properties文件列表。

當然,如果不想把參數(shù)文件寫在Spring以外,也可以在配置DBCP的時候直接將連接數(shù)據(jù)庫URL,用戶,密碼等等參數(shù)寫死在Spring當中也是可以的。

       3.6 如果整合iBATIS框架?

              iBATIS框架要工作的話,需要指定一個全局的iBATIS參數(shù)配置文件,即在Spring中需要告訴iBATIS框架,你工作時需要使用的參數(shù)文件在哪里可以找到,另外,Spring框架對常見的ORM框架等等都進行了封裝,所以要在Spring當中配置iBATIS框架的話,實際上要配置的類是Spring框架當中的某個類,如下:

 

       <bean id="sqlMapClient"

              class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">

              <property name="configLocations"

                     value="WEB-INF/sql-map-config.xml" />

              <property name="dataSource" ref="dataSource" />

       </bean>

       上面的配置參數(shù)中的value="WEB-INF/sql-map-config.xml"即是用來告訴iBATIS框架它要使用的配置參數(shù)文件存放在哪個位置。

       以上配置參數(shù)中的property name="dataSource" ref="dataSource"即是用來告訴iBATIS框架,它要使用的數(shù)據(jù)源是在3.5小節(jié)中配置的數(shù)據(jù)庫緩沖池。

       3.7 如何使用Spring 2.5 提供的AutoWired功能?

              Spring的參數(shù)配置文件中加入如下一行配置參數(shù)即可:

       <context:annotation-config />

       3.8 如何通過數(shù)據(jù)庫的表自動生成實體類以及參數(shù)配置文件等等?

              需要使用iBATIS官方網(wǎng)站提供的iBATOR,在Eclipse當中可以安裝該插件,Eclipse當中安裝插件的方法這里不做描述。

              安裝好iBATOR插件以后,用Eclipse的新建功能向項目中加入一個用于自動生成iBATIS實體類等的參數(shù)配置文件,在該文件當中指定本機上的JDBC數(shù)據(jù)驅(qū)動以及連接數(shù)據(jù)庫的參數(shù)等等,配置好要生成的實體類,DAOSQL映射文件的存放路徑,如果一切正常,配置完成以后即可自動根據(jù)數(shù)據(jù)庫當中的表結(jié)構(gòu)來產(chǎn)生實體類以及DAO等等。

       3.9 iBATOR生成的實體類以及DAO等如何應用?

              第一步需要先將生成的SQL映射文件添加到iBATIS的全局參數(shù)配置文件當中去,具體是哪一個文件是iBATIS框架的參數(shù)配置文件呢?3.6小節(jié)中的<property name="configLocations" value="WEB-INF/sql-map-config.xml" />這一行配置的是哪一個文件,那么那個文件就是iBATIS框架的全局配置參數(shù)文件。

       向里面加入某一個實體類對應的SQL映射文件的配置參數(shù)是如下格式:

       <sqlMap resource="edu/xw/ji/sqlmaps/t_db_history_SqlMap.xml" />

       3.10 Spring當中如何配置iBATOR自動生成的DAO類呢?

              iBATOR代碼生成工具自動生成的DAO類的實現(xiàn)類有些特殊,即DAO實現(xiàn)類在實例化的時候需要傳入一個構(gòu)造參數(shù),在3.6小節(jié)當中配置的那個類的數(shù)據(jù)類型就是這個構(gòu)造函數(shù)要傳入的參數(shù)數(shù)據(jù)類型,那么在Spring當中配置DAO實例時告訴它構(gòu)造函數(shù)的參數(shù)是什么就可以了,如下:

       <bean id="sys_job_type_dao"

              class="edu.xw.ji.dao.SysJobTypeDAOImpl">

              <constructor-arg>

                     <ref bean="sqlMapClient" />

              </constructor-arg>

       </bean>

       3.11 Spring如何管理Struts2Action類?

              要讓Struts2Action類與Spring一起工作,需要先在Spring當中定義bean,即將Struts2Action當成普通的bean定義在Spring當中,唯一需要注意的地方是要在Spring的配置參數(shù)當中加一句scope="prototype"。

              然后在Struts2的參數(shù)配置文件中再去使用這個在Spring當中定義好的bean id就行了。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
使用MyEclipse部署SSH框架
Struts 2框架整合Spring
XX智慧社區(qū)融合服務(wù)門戶詳細設(shè)計
Spring MVC 3.0.5 Spring 3.0.5 MyBatis3.0.4全注解...
rapid-framework v3.9新版本發(fā)布 - badqiu - JavaEye技...
eclipse搭建SSH框架詳解
更多類似文章 >>
生活服務(wù)
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服