日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術(shù)文章
文章詳情頁

Spring如何基于xml實(shí)現(xiàn)聲明式事務(wù)控制

瀏覽:139日期:2023-08-10 10:26:21

一、pom.xml

<?xml version='1.0' encoding='UTF-8'?><project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd'> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>A02spring</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <!--https://mvnrepository.com/artifact/org.springframework/spring-context--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.8.RELEASE</version> </dependency> <!--https://mvnrepository.com/artifact/org.springframework/spring-context--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>5.2.8.RELEASE</version> </dependency> <!--https://mvnrepository.com/artifact/org.springframework/spring-context--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>5.2.8.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.9.6</version> </dependency> <!--https://mvnrepository.com/artifact/org.springframework/spring-context--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> </dependency> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-test --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.2.8.RELEASE</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration> <source>1.8</source> <target>1.8</target></configuration> </plugin> </plugins> </build></project>

二、spring的xml配置文件

<?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:tx='http://www.springframework.org/schema/tx' xsi:schemaLocation=' http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd'> <bean class='com.wuxi.services.impl.AccountServiceImpl'> <property name='accountDao' ref='accountDao'></property> </bean> <bean class='com.wuxi.daos.impl.AccountDaoImpl'> <property name='dataSource' ref='dataSource'></property> </bean> <bean class='org.springframework.jdbc.datasource.DriverManagerDataSource'> <property name='driverClassName' value='com.mysql.cj.jdbc.Driver'></property> <property name='url' value='jdbc:mysql://192.168.2.105:3306/ssm?characterEncoding=utf8&useSSL=false'></property> <property name='username' value='root'></property> <property name='password' value='123456'></property> </bean><!--spring中基于xml的聲明式事務(wù)控制配置步驟 1、配置事務(wù)管理器 2、配置事務(wù)的通知 3、配置aop中的通用切入點(diǎn)表達(dá)式 4、建立事務(wù)通知和切入點(diǎn)表達(dá)式的對應(yīng)關(guān)系 5、配置事務(wù)的屬性--> <!--事務(wù)管理器--> <bean class='org.springframework.jdbc.datasource.DataSourceTransactionManager'> <property name='dataSource' ref='dataSource'></property> </bean> <!--事務(wù)的通知--> <tx:advice transaction-manager='transactionManager'> <!-- 事務(wù)的屬性 isolation:用于指定事務(wù)的隔離級別。默認(rèn)值是DEFAULE,表示使用數(shù)據(jù)庫的默認(rèn)隔離級別。 propagation:用于指定事務(wù)的傳播行為。默認(rèn)值是REQUIRED,表示一定會有事務(wù),增刪改的選擇。查詢方法可以選擇SUPPORTYS。 read-only:用于指定事務(wù)是否只讀。只有查詢方法才能設(shè)置為true。默認(rèn)值是false,表示讀寫。 timeout:用于指定事務(wù)的超時時間,默認(rèn)值是-1,表示永不超時,如果指定了數(shù)值,以秒為單位。 rollback-for:用于指定一個異常,當(dāng)產(chǎn)生該異常時,事務(wù)回滾,產(chǎn)生其他異常時,事務(wù)不回滾。沒有默認(rèn)值。表示任何異常都回滾。 no-rollback-for:用于指定一個異常,當(dāng)產(chǎn)生該異常時,事務(wù)不回滾,產(chǎn)生其他異常時事務(wù)回滾。沒有默認(rèn)值。表示任何異常都回滾。 --> <tx:attributes> <tx:method name='*' propagation='REQUIRED' read-only='false'/> <tx:method name='find*' propagation='SUPPORTS' read-only='true'/> </tx:attributes> </tx:advice> <aop:config> <!--切入點(diǎn)表達(dá)式--> <aop:pointcut expression='execution(* com.wuxi.services.*.*(..))'/> <!--切入點(diǎn)表達(dá)式和事務(wù)通知的對應(yīng)關(guān)系--> <aop:advisor advice-ref='txAdvice' pointcut-ref='ptc'></aop:advisor> </aop:config></beans>

三、實(shí)體類

package com.wuxi.beans;import lombok.Data;import java.io.Serializable;@Datapublic class Account implements Serializable { private Integer id; private String name; private Float money;}

四、dao

1、接口

package com.wuxi.daos;import com.wuxi.beans.Account;public interface AccountDao { Account findAccountById(Integer accountId); Account findAccountByName(String accountName); void updateAccount(Account account);}

2、實(shí)現(xiàn)類

package com.wuxi.daos.impl;import com.wuxi.beans.Account;import com.wuxi.daos.AccountDao;import org.springframework.jdbc.core.BeanPropertyRowMapper;import org.springframework.jdbc.core.support.JdbcDaoSupport;import java.util.List;public class AccountDaoImpl extends JdbcDaoSupport implements AccountDao { @Override public Account findAccountById(Integer accountId) { List<Account> accounts = getJdbcTemplate().query('select * from account where id = ?', new BeanPropertyRowMapper<Account>(Account.class), accountId); return accounts.isEmpty() ? null : accounts.get(0); } @Override public Account findAccountByName(String accountName) { List<Account> accounts = getJdbcTemplate().query('select * from account where name = ?', new BeanPropertyRowMapper<Account>(Account.class), accountName); if (accounts.isEmpty()) { return null; } if (accounts.size() > 1) { throw new RuntimeException('結(jié)果集不唯一'); } return accounts.get(0); } @Override public void updateAccount(Account account) { getJdbcTemplate().update('update account set name=?,money=? where id=?', account.getName(), account.getMoney(), account.getId()); }}

五、service

1、接口

package com.wuxi.services;import com.wuxi.beans.Account;public interface AccountService { Account findAccounById(Integer accountId); void transfer(String sourceName, String targetName, Float money);}

2、實(shí)現(xiàn)類

package com.wuxi.services.impl;import com.wuxi.beans.Account;import com.wuxi.daos.AccountDao;import com.wuxi.services.AccountService;public class AccountServiceImpl implements AccountService { private AccountDao accountDao; public void setAccountDao(AccountDao accountDao) { this.accountDao = accountDao; } @Override public Account findAccounById(Integer accountId) { return accountDao.findAccountById(accountId); } @Override public void transfer(String sourceName, String targetName, Float money) { Account source = accountDao.findAccountByName(sourceName); Account target = accountDao.findAccountByName(targetName); source.setMoney(source.getMoney() - money); target.setMoney(target.getMoney() + money); accountDao.updateAccount(source); int i = 1 / 0; accountDao.updateAccount(target); }}

六、測試

package com.wuxi.tests;import com.wuxi.services.AccountService;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = 'classpath:application.xml')public class MySpringTest { @Autowired private AccountService as; @Test public void testTransfer() { as.transfer('aaa', 'bbb', 100f); }}

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

標(biāo)簽: Spring
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
日韩一区二区中文| 老牛国产精品一区的观看方式| 蜜桃视频在线观看一区二区| 国产精品日韩久久久| 欧美一区=区| 亚洲精品字幕| 日韩精品国产精品| 国产日韩欧美三区| 欧美日韩一区二区三区在线电影| 国产欧美一区二区三区国产幕精品| 国产精品一区二区免费福利视频 | 青草综合视频| 国产精品亚洲二区| 女人天堂亚洲aⅴ在线观看| 国产精品xvideos88| 亚洲一区久久| 亚洲不卡视频| 久久精品一区二区国产| 精品国产三区在线| 欧洲在线一区| 丝袜诱惑制服诱惑色一区在线观看| 亚洲精品激情| 国产精品一区高清| 亚洲天堂av影院| 亚洲免费激情| 日本午夜精品| 久久av日韩| 欧美日韩亚洲在线观看| 蜜桃久久av| 国产精品国码视频| 在线视频观看日韩| 亚洲另类av| 国产精品15p| 99久久夜色精品国产亚洲1000部| 亚洲综合国产| 毛片不卡一区二区| 激情欧美一区| 日韩中文字幕一区二区高清99| 国产精品久久久久9999高清| 麻豆精品蜜桃| 亚洲欧洲国产精品一区| 国产精品久久| 图片区亚洲欧美小说区| 人人爱人人干婷婷丁香亚洲| 天堂а√在线最新版中文在线| 丝袜a∨在线一区二区三区不卡| 国产精品密蕾丝视频下载| 精品亚洲美女网站| 日韩美女国产精品| 蜜臀久久精品| 日本成人一区二区| 精精国产xxxx视频在线播放 | 久久久9色精品国产一区二区三区| 鲁大师成人一区二区三区| 久久99久久人婷婷精品综合| 久久久国产亚洲精品| 日本午夜精品视频在线观看| 日韩精品看片| 欧美亚洲二区| 国产韩日影视精品| 麻豆精品99| 免费看黄色91| 欧美gv在线| 国产欧美一区二区三区精品观看| 在线看片不卡| 国产一区精品福利| 亚洲免费专区| 欧美一级精品| 麻豆精品国产91久久久久久| 蜜桃久久精品一区二区| 国产一区二区精品福利地址| 蜜臀av亚洲一区中文字幕| 日韩福利一区| 国产精品草草| 亚洲精一区二区三区| 久久国产中文字幕| 久久亚洲国产精品尤物| 亚洲日本免费电影| 国产高清一区| 日韩欧美三级| 免费在线日韩av| 综合激情网...| 日韩国产网站| 国产一区二区三区黄网站 | 亚洲精品动态| 夜夜嗨一区二区| 久久久久欧美精品| 精品中文字幕一区二区三区四区| 四虎精品永久免费| 老牛国产精品一区的观看方式| 久久精品国语| 正在播放日韩精品| 精品久久网站| 国产精品v亚洲精品v日韩精品| 蜜桃一区二区三区在线观看| 欧美精选一区二区三区| 亚洲永久av| 激情中国色综合| 日本欧美在线| 婷婷五月色综合香五月| 人人精品人人爱| 伊人久久亚洲热| 久久要要av| 99久久久久国产精品| 亚洲精品成人图区| 色综合五月天| 中文字幕成在线观看| 精品国产乱码久久久久久樱花| 国产精品v亚洲精品v日韩精品| 久久国产精品免费一区二区三区| 日本免费一区二区视频| 伊人久久亚洲| 亚洲精品少妇| 麻豆成人在线| 蜜桃av一区二区三区电影| 视频一区二区三区在线| 久久亚洲一区| 蜜桃视频在线观看一区二区| 蜜桃久久久久久| 少妇精品在线| 欧美日韩18| 久久爱www成人| 成人综合一区| 97se综合| 亚洲香蕉网站| 亚洲一区二区免费看| 99国产精品| 蜜桃视频第一区免费观看| 老牛影视一区二区三区| 亚洲久久视频| 国产日韩欧美一区二区三区在线观看| 欧美中文一区| 久久精品国产福利| 粉嫩av一区二区三区四区五区 | 久久精品国内一区二区三区水蜜桃| 亚洲va中文在线播放免费| 久久九九电影| 久久电影一区| 日本不卡一区二区三区| 日本亚洲欧洲无免费码在线| 奇米亚洲欧美| 美女久久99| 欧美精品日日操| 女同性一区二区三区人了人一| 免费成人av在线播放| 日韩福利视频导航| 国产成人精品亚洲线观看| 久久精品在线| 中文字幕亚洲在线观看| 国产精成人品2018| 久久夜夜操妹子| 日本 国产 欧美色综合| 国产乱码精品一区二区亚洲| 成人国产综合| 99久久精品国产亚洲精品| 亚洲欧美日韩精品一区二区 | 国产日韩欧美一区| 日韩在线看片| 玖玖玖国产精品| 国产精品久久久久久模特| 天堂av在线| 免费看欧美美女黄的网站| 国产精品日韩精品在线播放| 中文在线а√天堂| 在线一区二区三区视频| 国产一区 二区| 91精品一区二区三区综合| 日韩美女精品| 久久久成人网| 欧美在线精品一区| 欧美日韩精品一区二区视频| 日韩av在线播放中文字幕| 日韩一区三区| 日韩福利视频网| 日韩不卡视频在线观看| 日韩不卡在线观看日韩不卡视频 | 亚洲www免费| 亚洲三级国产| 日韩免费小视频| 日韩国产欧美三级| 五月激情久久| 日韩精品三区四区| 日韩中文欧美| 青青国产91久久久久久| 国产综合色区在线观看| 日韩不卡在线观看日韩不卡视频 | 日本不卡视频在线| 蜜臀国产一区| 婷婷精品久久久久久久久久不卡| 高清日韩中文字幕| 蜜臀精品久久久久久蜜臀| 国产精品99一区二区三| 亚洲久久视频| 91精品一区二区三区综合| 久久a爱视频| 婷婷视频一区二区三区| 在线视频观看日韩| 国产成人精品亚洲线观看 | 免费看日韩精品| 精品日韩视频|