欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring整合MyBatis圖示過程解析

 更新時間:2019年11月05日 15:11:12   作者:林然無限好  
這篇文章主要介紹了Spring整合MyBatis圖示過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

這篇文章主要介紹了Spring整合MyBatis圖示過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

1.導(dǎo)入所需要的jar依賴

!--MyBatis和Spring的整合包 由MyBatis提供-->
<dependency>
 <groupId>org.mybatis</groupId>
 <artifactId>mybatis-spring</artifactId>
 <version>1.3.0</version>
</dependency>
<!--MyBatis的核心jar文件-->
<dependency>
 <groupId>org.mybatis</groupId>
 <artifactId>mybatis</artifactId>
 <version>3.4.1</version>
</dependency>

2.MyBatis和Spring整合(XML版)

1.dao接口

2.entity實體類

3.service層接口

4.serviceimpl實現(xiàn)類

5.PersonDao.xml配置

6.jdbc.properties配置

 7.大配置文件

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"

    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd

    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  <!--<context:component-scan base-package="com.spring"/>-->
  <!-- 配置數(shù)據(jù)源 spring內(nèi)置的數(shù)據(jù)源-->
  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driver}"></property>
    <property name="url" value="${jdbc.url}"></property>
    <property name="username" value="${jdbc.username}"></property>
    <property name="password" value="${jdbc.password}"></property>
  </bean>
  <!-- 引入屬性文件 -->
  <context:property-placeholder location="jdbc.properties.properties"/>
  <!--注冊DAO層:mapper的代理對象-->
  <bean id="personDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
    <property name="mapperInterface" value="com.spring.dao.PersonDao"></property>
    <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
  </bean>
  <!--配置service層對象-->
  <bean id="personService" class="com.spring.service.PersonServiceImpl">
    <property name="dao" ref="personDao"></property>
  </bean>
  <!-- sqlSessionFactory 創(chuàng)建SqlSession對象的工廠 -->
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <!-- Mybatis的大配置文件 -->
    <property name="typeAliasesPackage" value="com.spring.entity"></property>
    <!-- 掃描sql配置文件:mapper需要的xml文件 -->
    <property name="mapperLocations" value="classpath*:mapper/*.xml"/>
  </bean>
  <!-- MapperScannerConfigurer 掃描mapper文件掃描器 -->
  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.spring.dao"></property>
  </bean>

  <!-- transactionManager 事務(wù)管理器-->
  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
  </bean>
  <!-- 事務(wù)通知-->
  <tx:advice transaction-manager="transactionManager" id="txAdvice">
    <tx:attributes>
      <!--get系列方法設(shè)置事務(wù)的隔離級別和傳播行為-->
      <tx:method name="get*" isolation="READ_COMMITTED" propagation="REQUIRED"/>
    </tx:attributes>
  </tx:advice>
</beans>

8.測試類

結(jié)果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java中BigDecimal的基本運算(詳解)

    Java中BigDecimal的基本運算(詳解)

    下面小編就為大家?guī)硪黄狫ava中BigDecimal的基本運算(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • 使用spring aop 統(tǒng)一捕獲異常和寫日志的示例demo

    使用spring aop 統(tǒng)一捕獲異常和寫日志的示例demo

    本文通過一個小demo給大家介紹spring AOP 實現(xiàn)的異常捕獲和日志的方法技巧,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2021-08-08
  • 詳解redis與spring的整合(使用緩存)

    詳解redis與spring的整合(使用緩存)

    本篇文章主要介紹了redis與spring的整合(使用緩存),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • SpringBoot快速搭建web項目詳細(xì)步驟總結(jié)

    SpringBoot快速搭建web項目詳細(xì)步驟總結(jié)

    這篇文章主要介紹了SpringBoot快速搭建web項目詳細(xì)步驟總結(jié) ,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • spring profile 多環(huán)境配置管理詳解

    spring profile 多環(huán)境配置管理詳解

    這篇文章主要介紹了 spring profile 多環(huán)境配置管理詳解的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • 詳解spring cloud分布式整合zipkin的鏈路跟蹤

    詳解spring cloud分布式整合zipkin的鏈路跟蹤

    這篇文章主要介紹了詳解spring cloud分布式整合zipkin的鏈路跟蹤,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • IDEA新建bootstrap.yml文件不顯示葉子圖標(biāo)的問題

    IDEA新建bootstrap.yml文件不顯示葉子圖標(biāo)的問題

    這篇文章主要介紹了IDEA新建bootstrap.yml文件不顯示葉子圖標(biāo)的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Java設(shè)計模式之代理模式

    Java設(shè)計模式之代理模式

    這篇文章介紹了Java設(shè)計模式之代理模式,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-09-09
  • 使用spring的IOC解決程序耦合的方法

    使用spring的IOC解決程序耦合的方法

    這篇文章主要介紹了使用spring的IOC解決程序耦合的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • SpringBoot實現(xiàn)動態(tài)數(shù)據(jù)源切換的項目實踐

    SpringBoot實現(xiàn)動態(tài)數(shù)據(jù)源切換的項目實踐

    在實際開發(fā)過程中,我們經(jīng)常遇到需要同時操作多個數(shù)據(jù)源的情況,本文主要介紹了SpringBoot實現(xiàn)動態(tài)數(shù)據(jù)源切換的項目實踐,具有一定的參考價值,感興趣的可以了解一下
    2024-04-04

最新評論