Java開發(fā)之ssm三大框架整合_第1頁
Java開發(fā)之ssm三大框架整合_第2頁
Java開發(fā)之ssm三大框架整合_第3頁
Java開發(fā)之ssm三大框架整合_第4頁
Java開發(fā)之ssm三大框架整合_第5頁
已閱讀5頁,還剩3頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

第Java開發(fā)之ssm三大框架整合目錄1.springmvc2.spring-dao.xml與mybatis-config.xml3.spring-service.xml4.引用

1.springmvc

和只有spring-mvc時(shí)一樣,web.xmlspring-mvc.xml

spring-mvc.xml

beansxmlns="/schema/beans"

xmlns:xsi="/2001/XMLSchema-instance"

xmlns:context="/schema/context"

xmlns:mvc="/schema/cache"

xsi:schemaLocation="/schema/beans/schema/beans/spring-beans.xsd/schema/context/schema/context/spring-context.xsd/schema/cache/schema/cache/spring-cache.xsd"

!--注解驅(qū)動(dòng)--

mvc:annotation-driven/

!--靜態(tài)資源過濾--

!--開啟jsp專用的視圖控制器internalresourceresoler--

bean

!--設(shè)置前綴--

propertyname="prefix"value="/WEB-INF/templates/"/property

!--設(shè)置后綴--

propertyname="suffix"value=".jsp"/property

/bean

!--掃描controller注解--

context:component-scanbase-package="com.hxut.rj1192.zyk.Controller"/context:component-scan

/beans

web.xml

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

web-appxmlns="/xml/ns/javaee"

xmlns:xsi="/2001/XMLSchema-instance"

xsi:schemaLocation="/xml/ns/javaee/xml/ns/javaee/web-app_4_0.xsd"

version="4.0"

!--設(shè)置攔截器,解決參數(shù)亂碼,一定要在設(shè)置HiddenHttpMethodFilter請求前,要在其他攔截器和servlet執(zhí)行前設(shè)置編碼--

filter

filter-nameparamencoding/filter-name

filter-classorg.springframework.web.filter.CharacterEncodingFilter/filter-class

init-param

param-nameencoding/param-name

param-valueutf-8/param-value

/init-param

!--解決返回的請求數(shù)亂碼response--

init-param

param-nameforceResponseEncoding/param-name

param-valuetrue/param-value

/init-param

/filter

!--攔截所有頁面--

filter-mapping

filter-nameparamencoding/filter-name

url-pattern/*/url-pattern

/filter-mapping

!--servlet將所有除了jsp的頁面攔截,交給dispatcherservlet視圖控制器,并設(shè)置dispatcherservlet的xml文件的位置--

servlet-mapping

servlet-nameall/servlet-name

url-pattern//url-pattern

/servlet-mapping

servlet

servlet-nameall/servlet-name

servlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-class

init-param

param-namecontextConfigLocation/param-name

param-valueclasspath:Spring-springmvc.xml/param-value

/init-param

/servlet

!--攔截所有請求,并交給hiddenhttpmethodfilter檢測否是post請求,且_method不為空,如果是,就將請求類型改為_method的值--

filter

filter-namehiddenHttpMethodFilter/filter-name

filter-classorg.springframework.web.filter.HiddenHttpMethodFilter/filter-class

/filter

filter-mapping

filter-namehiddenHttpMethodFilter/filter-name

url-pattern/*/url-pattern

/filter-mapping

/web-app

2.spring-dao.xml與mybatis-config.xml

主要就是spring整合mybatis

spring整合mybatis

在上面的基礎(chǔ)上,去掉成接口的實(shí)現(xiàn)類了,需要配置dao接口掃描包,我的理解是這個(gè)dao接口掃描包中有datasource,有mapper的掃描范圍,它會(huì)自動(dòng)生成這些接口對應(yīng)的mapper,并將接口的mapper放到xml文件中,所以在spring-service中,直接

propertyname=bookmapperref=bookmapper/property

引用即可

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

beansxmlns="/schema/beans"

xmlns:xsi="/2001/XMLSchema-instance"

xmlns:context="/schema/context"

xsi:schemaLocation="/schema/beans

/schema/beans/spring-beans.xsd

/schema/context

/schema/context/spring-context.xsd"

!--讀取數(shù)據(jù)庫配置文件--

context:property-placeholderlocation="classpath:perties"/context:property-placeholder

beanid="dataSource"

propertyname="driverClass"value="${jdbc.driver}"/

propertyname="jdbcUrl"value="${jdbc.url}"/

propertyname="user"value="${jdbc.username}"/

propertyname="password"value="${jdbc.password}"/

propertyname="maxPoolSize"value="30"/

propertyname="minPoolSize"value="10"/

!--關(guān)閉連接后不自動(dòng)commit--

propertyname="autoCommitOnClose"value="false"/

!--獲取連接超時(shí)時(shí)間--

propertyname="checkoutTimeout"value="10000"/

!--當(dāng)獲取連接失敗重試次數(shù)--

propertyname="acquireRetryAttempts"value="2"/

/bean

beanid="sqlsessionFactory"

propertyname="dataSource"ref="dataSource"/property

propertyname="configLocation"value="classpath:mybatis-config.xml"/property

/bean

!--配置dao接口掃描包,動(dòng)態(tài)的實(shí)現(xiàn)了dao接口可以注入到spring容器中

就是用來代替BookMapperImpl類--

bean

!--注入sqlsessionfactory--

!--個(gè)人理解,這個(gè)dao接口掃描包中有datasource,有mapper的掃描范圍,

它會(huì)自動(dòng)生成這些接口對應(yīng)的mapper,并將接口的mapper放到xml文件中,所以在spring-service中,直接

propertyname="bookmapper"ref="bookmapper"/property引用即可--

propertyname="sqlSessionFactoryBeanName"value="sqlsessionFactory"/property

!--要掃描的dao包,會(huì)自動(dòng)生成包下的類的接口的實(shí)現(xiàn)類--

propertyname="basePackage"value="com.hxut.rj1192.zyk"/property

/bean

/beans

mybatis-config.xml詳細(xì)在上面的mybatis整合spring的文章中,它做兩件事,配置映射文件路徑,配置接口掃描范圍,它被import到spring-dao.xml中。

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

!DOCTYPEconfiguration

PUBLIC"-////DTDConfig3.0//EN"

"/dtd/mybatis-3-config.dtd"

configuration

!--配置數(shù)據(jù)源交給spring了--

!--給類起別名--

typeAliases

packagename="com.hxut.rj1192.zyk.mapper"/

/typeAliases

!--設(shè)置映射文件路徑--

mappers

mapperresource="com/hxut/rj1192/zyk/mapper/Bookmapper.xml"/mapper

/mappers

/configuration

3.spring-service.xml

在這個(gè)文件中要進(jìn)行事務(wù)的處理(事務(wù)本來就應(yīng)該是在service層),要將service層的類全部放到ioc容器中,然后這些類中因?yàn)檎{(diào)用了dao層的類,然后因?yàn)閯偛诺诙颗渲昧私涌趻呙璋?,直接ref獲取mapper即可

beansxmlns="/schema/beans"

xmlns:xsi="/2001/XMLSchema-instance"

xmlns:context="/schema/context"

xsi:schemaLocation="/schema/beans

/schema/beans/spring-beans.xsd

/schema/context

/schema/context/spring-context.xsd"

!--開啟注解驅(qū)動(dòng)--

context:component-scanbase-package="com.hxut.rj1192.zyk.service"/context:component-scan

beanid="booksServiceimpl"

propertyname="bookmapper"ref="bookmapper"/property

/bean

!--聲明式事務(wù)--

beanid="t

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論