大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

Spring框架教程
Spring IOC控制反轉(zhuǎn)
Spring AOP面向切面編程
Spring集成MyBatis
Spring事務(wù)
Spring與Web

Spring事務(wù)環(huán)境搭建實例

舉例:購買商品trans_sale項目

本例要實現(xiàn)購買商品,模擬用戶下訂單,向訂單表添加銷售記錄,從商品表減少庫存。

實現(xiàn)步驟:

Step0:創(chuàng)建數(shù)據(jù)庫表

創(chuàng)建兩個數(shù)據(jù)庫表sale , goods

sale 銷售表

goods 商品表

goods表數(shù)據(jù)

Step1: maven依賴 pom.xml

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.16.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.3.16.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.3.16.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.12</version>
        </dependency>
    </dependencies>
<build>
    <resources>
      <resource>
        <directory>src/main/java</directory><!--所在的目錄-->
        <includes><!--包括目錄下的.properties,.xml文件都會掃描到-->
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
 </build>

Step2:創(chuàng)建實體類

創(chuàng)建實體類Sale與Goods

Step3:定義dao接口

定義兩個dao的接口SaleDao , GoodsDao

Step4:定義dao接口對應(yīng)的sql映射文件

SaleDao.xml

GoodsDao.xml

Step5:定義異常類

定義service層可能會拋出的異常類NotEnoughException

Step6:定義Service接口

定義Service接口BuyGoodsService

Step7:定義service的實現(xiàn)類

定義service層接口的實現(xiàn)類BuyGoodsServiceImpl

● 類定義

● Dao屬性

● Buy方法

Step8:修改Spring配置文件內(nèi)容

聲明Mybatis對象

聲明業(yè)務(wù)層對象

Step9:定義測試類

定義測試類MyTest。現(xiàn)在就可以在無事務(wù)代理的情況下運行了。

全部教程
主站蜘蛛池模板: 69视频在线观看福利视频 | 国产亚洲欧美成人久久片 | 久久资源总站 | 综合欧美日韩一区二区三区 | 青青青国产免费全部免费观看 | 久久亚洲国产精品一区二区 | 欧美精品久久久久久久影视 | 玖玖成人网 | 女人十八一级毛片 | 丁香色综合 | 亚洲天天做日日摸天天做 | 91精选| 日本免费不卡 | 久久天天躁夜夜躁狠狠 | 中文一区二区视频 | 亚洲视频免 | 九九99久久精品午夜剧场免费 | 老子不卡 | 亚洲一区视频在线 | 久久这里只有精品首页 | 亚洲精品tv久久久久久久久久 | 日韩亚洲一区中文字幕在线 | 亚洲人成自拍网站在线观看忄 | 波多野结衣国产一区二区三区 | 狼人射综合 | 成人欧美一区二区三区黑人妖 | 97久久伊人精品影院 | 高清色视频 | 国产精品国产自线在线观看 | 69色视频日韩在线视频 | 一级毛片a免费播放王色 | 亚洲欧美一区二区三区国产精品 | 美国特级成人毛片 | 老妇激情毛片免费 | 性短视频在线观看免费不卡流畅 | 99热久久这里只有精品在 | 天堂国产| 很黄很色的小视频在线网站 | 老子午夜伦影理论片 | 国产欧美精品一区二区三区–老狼 | 97av在线播放|