最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java開(kāi)發(fā)之ssm三大框架整合

 更新時(shí)間:2022年05月16日 09:18:35   作者:仰望星空的快樂(lè)  
SSM框架是spring?MVC?,spring和mybatis框架的整合,是標(biāo)準(zhǔn)的MVC模式,將整個(gè)系統(tǒng)劃分為表現(xiàn)層,controller層,service層,DAO層四層,使用spring?MVC負(fù)責(zé)請(qǐng)求的轉(zhuǎn)發(fā)和視圖管理,spring實(shí)現(xiàn)業(yè)務(wù)對(duì)象管理,mybatis作為數(shù)據(jù)對(duì)象的持久化引擎

1.springmvc

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

spring-mvc.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/cache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!--    注解驅(qū)動(dòng)-->
    <mvc:annotation-driven/>
<!--    靜態(tài)資源過(guò)濾-->
<!--    開(kāi)啟jsp專(zhuān)用的視圖控制器 internalresourceresoler-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--    設(shè)置前綴-->
        <property name="prefix" value="/WEB-INF/templates/"></property>
        <!--    設(shè)置后綴-->
        <property name="suffix" value=".jsp"></property>
    </bean>
<!--    掃描 controller注解-->
    <context:component-scan base-package="com.hxut.rj1192.zyk.Controller"></context:component-scan>
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
<!--    設(shè)置攔截器,解決參數(shù)亂碼,一定要在設(shè)置HiddenHttpMethodFilter請(qǐng)求前,要在其他攔截器和servlet執(zhí)行前設(shè)置編碼-->
    <filter>
        <filter-name>paramencoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
      <init-param>
          <param-name>encoding</param-name>
          <param-value>utf-8</param-value>
      </init-param>
<!--        解決返回的請(qǐng)求數(shù)亂碼  response-->
        <init-param>
            <param-name>forceResponseEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
<!--攔截所有頁(yè)面-->
    <filter-mapping>
        <filter-name>paramencoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
<!--servlet 將所有除了jsp的頁(yè)面攔截,交給dispatcherservlet視圖控制器,并設(shè)置dispatcherservlet的xml文件的位置-->
    <servlet-mapping>
        <servlet-name>all</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>all</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:Spring-springmvc.xml</param-value>
        </init-param>
    </servlet>
<!-- 攔截所有請(qǐng)求,并交給hiddenhttpmethodfilter 檢測(cè)否是post請(qǐng)求,且_method不為空,如果是,就將請(qǐng)求類(lèi)型改為_(kāi)method的值-->
    <filter>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>hiddenHttpMethodFilter</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)類(lèi)了,需要配置dao接口掃描包,我的理解是這個(gè)dao接口掃描包中有datasource,有mapper的掃描范圍, 它會(huì)自動(dòng)生成這些接口對(duì)應(yīng)的mapper,并將接口的mapper放到xml文件中,所以在spring-service中,直接

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

引用即可

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
       https://www.springframwork.org/schema/context/spring-context.xsd">
    <!-- 讀取數(shù)據(jù)庫(kù)配置文件-->
    <context:property-placeholder location="classpath:database.properties"></context:property-placeholder>
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="maxPoolSize" value="30"/>
        <property name="minPoolSize" value="10"/>
        <!-- 關(guān)閉連接后不自動(dòng)commit -->
        <property name="autoCommitOnClose" value="false"/>
        <!-- 獲取連接超時(shí)時(shí)間 -->
        <property name="checkoutTimeout" value="10000"/>
        <!-- 當(dāng)獲取連接失敗重試次數(shù) -->
        <property name="acquireRetryAttempts" value="2"/>
    </bean>
    <bean id="sqlsessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
    </bean>
<!--配置dao接口掃描包 ,動(dòng)態(tài)的實(shí)現(xiàn)了dao接口可以注入到spring容器中
  就是用來(lái)代替BookMapperImpl類(lèi) -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--        注入sqlsessionfactory-->
<!--個(gè)人理解,這個(gè)dao接口掃描包中有datasource,有mapper的掃描范圍,
它會(huì)自動(dòng)生成這些接口對(duì)應(yīng)的mapper,并將接口的mapper放到xml文件中,所以在spring-service中,直接
   <property name="bookmapper" ref="bookmapper"></property> 引用即可-->
        <property name="sqlSessionFactoryBeanName" value="sqlsessionFactory"></property>
<!--        要掃描的dao包, 會(huì)自動(dòng)生成包下的類(lèi)的接口的實(shí)現(xiàn)類(lèi)-->
        <property name="basePackage" value="com.hxut.rj1192.zyk"></property>
    </bean>
</beans>

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

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--    配置數(shù)據(jù)源交給spring了-->
    <!--    給類(lèi)起別名-->
    <typeAliases>
        <package name="com.hxut.rj1192.zyk.mapper"/>
    </typeAliases>
    <!--    設(shè)置映射文件路徑-->
    <mappers>
        <mapper resource="com/hxut/rj1192/zyk/mapper/Bookmapper.xml"></mapper>
    </mappers>
</configuration>

3.spring-service.xml

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

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
       https://www.springframwork.org/schema/context/spring-context.xsd">
<!--    開(kāi)啟注解驅(qū)動(dòng)-->
    <context:component-scan base-package="com.hxut.rj1192.zyk.service"></context:component-scan>
    <bean id="booksServiceimpl" class="com.hxut.rj1192.zyk.service.BooksServiceimpl">
        <property name="bookmapper" ref="bookmapper"></property>
    </bean>
<!--    聲明式事務(wù)-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!--       注入數(shù)據(jù)源 -->
        <property name="dataSource" ref="dataSource"></property>
    </bean>
</beans>

4.引用

將這些文件的引用放到一個(gè)大的xml文件中,這個(gè)文件只放引用,這樣就很容易看

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">
    <import resource="applicationContext.xml"></import>
    <import resource="spring-dao.xml"></import>
    <import resource="Spring-Service.xml"></import>
    <import resource="Spring-springmvc.xml"></import>
</beans>

或者在project structure中設(shè)置 spring application context,效果是一樣的

到此這篇關(guān)于Java開(kāi)發(fā)之ssm三大框架整合的文章就介紹到這了,更多相關(guān)Java ssm框架整合內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java實(shí)現(xiàn)歸并排序算法

    java實(shí)現(xiàn)歸并排序算法

    在學(xué)習(xí)算法的過(guò)程中,我們難免會(huì)接觸很多和排序相關(guān)的算法??偠灾?,對(duì)于任何編程人員來(lái)說(shuō),基本的排序算法是必須要掌握的。那么現(xiàn)在我們將要進(jìn)行基本的歸并排序算法的講解
    2016-01-01
  • Java 將文件轉(zhuǎn)為字節(jié)數(shù)組知識(shí)總結(jié)及實(shí)例詳解

    Java 將文件轉(zhuǎn)為字節(jié)數(shù)組知識(shí)總結(jié)及實(shí)例詳解

    這篇文章主要介紹了Java 將文件轉(zhuǎn)為字節(jié)數(shù)組實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • 詳解基于SpringBoot使用AOP技術(shù)實(shí)現(xiàn)操作日志管理

    詳解基于SpringBoot使用AOP技術(shù)實(shí)現(xiàn)操作日志管理

    這篇文章主要介紹了詳解基于SpringBoot使用AOP技術(shù)實(shí)現(xiàn)操作日志管理,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • myeclipse導(dǎo)出可運(yùn)行jar包簡(jiǎn)介

    myeclipse導(dǎo)出可運(yùn)行jar包簡(jiǎn)介

    這篇文章主要介紹了myeclipse導(dǎo)出可運(yùn)行jar包簡(jiǎn)介,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-11-11
  • SpringBoot應(yīng)用啟動(dòng)慢的原因分析及優(yōu)化方法

    SpringBoot應(yīng)用啟動(dòng)慢的原因分析及優(yōu)化方法

    在使用Spring Boot進(jìn)行開(kāi)發(fā)時(shí),快速啟動(dòng)應(yīng)用程序是一個(gè)非常重要的需求,然而,在某些情況下,我們會(huì)遇到Spring Boot應(yīng)用啟動(dòng)緩慢的問(wèn)題,本文將分析Spring Boot應(yīng)用啟動(dòng)慢的常見(jiàn)原因,并提供一些優(yōu)化方法,需要的朋友可以參考下
    2024-08-08
  • Spring?Security用戶定義?

    Spring?Security用戶定義?

    這篇文章主要介紹了Spring?Security用戶定義,大家都知道?Spring?Security的用戶定義有很多方式,其實(shí)主要有兩種,基于內(nèi)存的和基于數(shù)據(jù)庫(kù)的,下面我給大家簡(jiǎn)單介紹一下這兩種方式,需要的朋友可以參考下
    2022-02-02
  • 使用Mybatis更新時(shí)候只更新變更部分的方法

    使用Mybatis更新時(shí)候只更新變更部分的方法

    這篇文章主要介紹了使用Mybatis更新時(shí)候只更新變更部分的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Java進(jìn)行Appium自動(dòng)化測(cè)試的實(shí)現(xiàn)

    Java進(jìn)行Appium自動(dòng)化測(cè)試的實(shí)現(xiàn)

    這篇文章主要介紹了Java進(jìn)行Appium自動(dòng)化測(cè)試的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • JMeter自定義日志與日志分析的實(shí)現(xiàn)

    JMeter自定義日志與日志分析的實(shí)現(xiàn)

    JMeter與Java程序一樣,會(huì)記錄事件日志,本文就介紹一下JMeter自定義日志與日志分析的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • JAVA使用Ip2region獲取IP定位信息的操作方法

    JAVA使用Ip2region獲取IP定位信息的操作方法

    這篇文章主要介紹了JAVA使用Ip2region獲取IP定位信息,ip2region?-?是國(guó)內(nèi)開(kāi)發(fā)者開(kāi)發(fā)的離線IP地址定位庫(kù),針對(duì)國(guó)內(nèi)IP效果較好,國(guó)外的部分IP只能顯示國(guó)家,對(duì)java獲取IP定位信息操作過(guò)程感興趣的朋友一起看看吧
    2022-05-05

最新評(píng)論

甘泉县| 衡阳县| 天峨县| 柯坪县| 贵州省| 稷山县| 望奎县| 亚东县| 顺平县| 无为县| 雷州市| 白玉县| 江门市| 甘孜县| 新安县| 曲松县| 泾阳县| 宜州市| 福安市| 松滋市| 阳山县| 县级市| 广南县| 新晃| 杭锦后旗| 咸宁市| 大冶市| 麦盖提县| 屏东县| 黎平县| 洞口县| 孟村| 南华县| 车险| 宁南县| 商城县| 攀枝花市| 河西区| 沙洋县| 安化县| 绥芬河市|