中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

提供網(wǎng)站建設(shè)備案公司微信上怎么做廣告推廣

提供網(wǎng)站建設(shè)備案公司,微信上怎么做廣告推廣,東莞市環(huán)保局網(wǎng)站如何做登記表,py可以做網(wǎng)站嗎文章目錄一、聲明式事務(wù)之全注解式開發(fā)1、新建springConfig類2、測試程序3、測試結(jié)果二、聲明式事務(wù)之XML實(shí)現(xiàn)方式1、配置步驟2、測試程序3、運(yùn)行結(jié)果附一、聲明式事務(wù)之全注解式開發(fā) 基于之前的銀行轉(zhuǎn)賬系統(tǒng),將spring.xml配置文件嘎掉,變成全注解式開發(fā)…

文章目錄

  • 一、聲明式事務(wù)之全注解式開發(fā)
    • 1、新建springConfig類
    • 2、測試程序
    • 3、測試結(jié)果
  • 二、聲明式事務(wù)之XML實(shí)現(xiàn)方式
    • 1、配置步驟
    • 2、測試程序
    • 3、運(yùn)行結(jié)果


一、聲明式事務(wù)之全注解式開發(fā)

基于之前的銀行轉(zhuǎn)賬系統(tǒng),將spring.xml配置文件嘎掉,變成全注解式開發(fā)。
加入事務(wù)的銀行轉(zhuǎn)賬

原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: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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><context:component-scan base-package="com.powernode.bank"></context:component-scan><!--配置數(shù)據(jù)源--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/dududu"></property><property name="username" value="root"></property><property name="password" value="123456"></property></bean><!--配置JDBCTemplate--><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource"></property></bean><!--配置事務(wù)管理器--><bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!--事務(wù)注解驅(qū)動(dòng)器--><tx:annotation-driven transaction-manager="txManager"></tx:annotation-driven></beans>

1、新建springConfig類

1、@Configuration:表示代替spring.xml配置文件,在這個(gè)類當(dāng)中完成配置
2、@ComponentScan(“com.powernode.bank”):代替spring.xml文件中的組件掃描
3、@EnableTransactionManagement:代替spring.xml文件中的事務(wù)注解驅(qū)動(dòng)器

@Configuration  //表示代替spring.xml配置文件,在這個(gè)類當(dāng)中完成配置
@ComponentScan("com.powernode.bank")
@EnableTransactionManagement //代替事務(wù)注解驅(qū)動(dòng)器
public class springConfig {
}

spring.xml文件中還剩余3個(gè)bean,都有屬性、值。

<!--配置數(shù)據(jù)源--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/dududu"></property><property name="username" value="root"></property><property name="password" value="123456"></property></bean><!--配置JDBCTemplate--><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource"></property></bean><!--配置事務(wù)管理器--><bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean>

4、@Bean+get方法,并且get方法執(zhí)行結(jié)束的返回值要求是spring.xml文件里bean標(biāo)簽的class對(duì)象

//spring框架看到這個(gè)@Bean注解后,會(huì)調(diào)用這個(gè)被標(biāo)注的方法,這個(gè)方法的返回值是一個(gè)Java對(duì)象,這個(gè)Java對(duì)象會(huì)自動(dòng)納入IoC容器管理//返回的對(duì)象就是spring容器當(dāng)中Bean對(duì)象@Bean(name = "dataSource")public DruidDataSource getDataSource(){DruidDataSource dataSource = new DruidDataSource();dataSource.setDriverClassName("com.mysql.jdbc.Driver");dataSource.setUrl("jdbc:mysql://localhost:3306/dududu");dataSource.setUsername("root");dataSource.setPassword("123456");return dataSource;}@Bean(name = "jdbcTemplate")public JdbcTemplate getJdbcTemplate(DataSource dataSource){ //spring在調(diào)用這個(gè)方法的時(shí)候會(huì)自動(dòng)給我們傳遞過來一個(gè)dataSource對(duì)象JdbcTemplate jdbcTemplate = new JdbcTemplate();jdbcTemplate.setDataSource(dataSource);return jdbcTemplate;}@Bean(name = "txManager")public DataSourceTransactionManager getTxManager(DataSource dataSource){DataSourceTransactionManager txManager = new DataSourceTransactionManager();txManager.setDataSource(dataSource);return txManager;}

2、測試程序

在這里插入圖片描述

    @Testpublic void testNoXML(){ApplicationContext ac = new AnnotationConfigApplicationContext(springConfig.class);AccountService accountService = (AccountService) ac.getBean("accountService");try {accountService.transfer("act_001","act_002",10000);System.out.println("轉(zhuǎn)賬成功");}catch (Exception e){e.printStackTrace();System.out.println("轉(zhuǎn)賬失敗");}}

3、測試結(jié)果

在這里插入圖片描述
在這里插入圖片描述
模擬異常,事務(wù)依然可以起作用,錢不會(huì)丟。

在這里插入圖片描述
在這里插入圖片描述

二、聲明式事務(wù)之XML實(shí)現(xiàn)方式

全XML式開發(fā),不使用注解。
那么原spring.xml文件中的事務(wù)注解驅(qū)動(dòng)就需要嘎掉

    <!--事務(wù)注解驅(qū)動(dòng)器--><tx:annotation-driven transaction-manager="txManager"></tx:annotation-driven>

嘎掉之后,那應(yīng)該怎么添加事務(wù)?

再創(chuàng)建一個(gè)工程 為了不和原來的混在一起
在這里插入圖片描述
AccountServiceImpl業(yè)務(wù)實(shí)現(xiàn)類中,基于事務(wù)的注解@Transactional刪掉,原spring.xml文件中的事務(wù)注解驅(qū)動(dòng)就需要嘎掉,pom文件中添加aspectj依賴,

1、配置步驟

  • 第一步:配置事務(wù)管理器
  • 第二步:配置通知
  • 第三步:配置切面

pps:需要添加AspectJ的依賴、添加aop命名空間

    <!--配置通知--><tx:advice id="txAdvice" transaction-manager="txManager"><!--配置通知的相關(guān)屬性--><tx:attributes><!--之前所講的事務(wù)屬性,都可以在這個(gè)標(biāo)簽中配置--><tx:method name="transfer" propagation="REQUIRED" rollback-for="java.lang.Throwable"/></tx:attributes></tx:advice><!--配置切面--><aop:config><aop:pointcut id="txPointcut" expression="execution(* com.powernode.service..* (..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"></aop:advisor></aop:config>

<tx:method name=“transfer” propagation=“REQUIRED” rollback-for=“java.lang.Throwable”/>這里一般不會(huì)寫具體的方法,可以采用通配符的方式。
<tx:method name=“save*” propagation=“REQUIRED” rollback-for=“java.lang.Throwable”/>
<tx:method name=“delete*” propagation=“REQUIRED” rollback-for=“java.lang.Throwable”/>
<tx:method name=“insert*” propagation=“REQUIRED” rollback-for=“java.lang.Throwable”/>
<tx:method name=“modify*” propagation=“REQUIRED” rollback-for=“java.lang.Throwable”/>
<tx:method name=“query*” propagation=“REQUIRED” rollback-for=“java.lang.Throwable”/>
<tx:method name=“find*” propagation=“REQUIRED” rollback-for=“java.lang.Throwable”/>
<tx:method name=“get*” propagation=“REQUIRED” rollback-for=“java.lang.Throwable”/>
等等

2、測試程序

    @Testpublic void testNoAnnotation(){ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");AccountService accountService = ac.getBean("accountService", AccountService.class);try{accountService.transfer("act_001","act_002",20000);System.out.println("轉(zhuǎn)賬成功");}catch(Exception e){e.printStackTrace();System.out.println("轉(zhuǎn)賬失敗");}}

在這里插入圖片描述

3、運(yùn)行結(jié)果

在這里插入圖片描述

在這里插入圖片描述

模擬異常:
空指針異常 事務(wù)回滾
在這里插入圖片描述

在這里插入圖片描述
錢不會(huì)丟

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:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><context:component-scan base-package="com.powernode"></context:component-scan><!--配置數(shù)據(jù)源--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/dududu"></property><property name="username" value="root"></property><property name="password" value="123456"></property></bean><!--配置JDBCTemplate--><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource"></property></bean><!--配置事務(wù)管理器--><bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!--配置通知--><tx:advice id="txAdvice" transaction-manager="txManager"><!--配置通知的相關(guān)屬性--><tx:attributes><!--之前所講的事務(wù)屬性,都可以在這個(gè)標(biāo)簽中配置--><tx:method name="transfer" propagation="REQUIRED" rollback-for="java.lang.Throwable"/></tx:attributes></tx:advice><!--配置切面--><aop:config><aop:pointcut id="txPointcut" expression="execution(* com.powernode.service..* (..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"></aop:advisor></aop:config>
</beans>

http://www.risenshineclean.com/news/50612.html

相關(guān)文章:

  • 吳江和城鄉(xiāng)建設(shè)局網(wǎng)站關(guān)鍵信息基礎(chǔ)設(shè)施安全保護(hù)條例
  • 企業(yè)網(wǎng)站 流程推廣產(chǎn)品怎么發(fā)朋友圈
  • 做網(wǎng)站要看什么書百度搜索廣告收費(fèi)標(biāo)準(zhǔn)
  • 做問卷的幾個(gè)網(wǎng)站如何優(yōu)化關(guān)鍵詞的排名
  • 國家建設(shè)部人才交流中心網(wǎng)站廣告公司收費(fèi)價(jià)格表
  • 免費(fèi)單頁網(wǎng)站在線制作營銷軟文500字
  • dw做網(wǎng)站小技巧東莞網(wǎng)絡(luò)營銷公司
  • 如何創(chuàng)建一個(gè)平臺(tái)型公司優(yōu)化網(wǎng)站seo策略
  • 廣州網(wǎng)站制作公司優(yōu)化百度競價(jià)查詢
  • 企業(yè)網(wǎng)站建設(shè)公司排名河南省網(wǎng)站
  • 紅河州網(wǎng)站建設(shè)制作深圳市企業(yè)網(wǎng)站seo營銷工具
  • 廊坊網(wǎng)站建設(shè)外包如何網(wǎng)絡(luò)媒體推廣
  • 郴州網(wǎng)站設(shè)計(jì)較好的公司東莞網(wǎng)絡(luò)優(yōu)化公司
  • 新手做網(wǎng)站教程seo關(guān)鍵詞布局案例
  • wordpress文章隱藏內(nèi)容seo資訊網(wǎng)
  • 如何做發(fā)表文章的網(wǎng)站百度推廣計(jì)劃
  • 同一產(chǎn)品做多個(gè)網(wǎng)站江門網(wǎng)站開發(fā)多少錢
  • 微商城網(wǎng)站開發(fā)網(wǎng)絡(luò)推廣的工作內(nèi)容
  • 個(gè)人工作室網(wǎng)站模板武漢seo托管公司
  • 手機(jī)網(wǎng)站開發(fā)之列表開發(fā)成人營銷管理培訓(xùn)班
  • 哪家公司做網(wǎng)站便宜網(wǎng)絡(luò)營銷推廣系統(tǒng)
  • 網(wǎng)站開發(fā)的發(fā)展的前景專業(yè)提升關(guān)鍵詞排名工具
  • webhost wordpressseo關(guān)鍵詞搜索優(yōu)化
  • 網(wǎng)站建設(shè)湖南青島網(wǎng)站優(yōu)化公司
  • 備案沒有商城可以做商城網(wǎng)站嗎中國今日新聞
  • 實(shí)力網(wǎng)站建設(shè)百度打開
  • 自己怎么做視頻網(wǎng)站百度快照優(yōu)化排名推廣
  • 濮陽做網(wǎng)站的公司有哪些谷歌搜索引擎下載
  • 特效相冊(cè)網(wǎng)站源碼百度app官網(wǎng)下載安裝
  • 做網(wǎng)站實(shí)現(xiàn)登陸功能十八大禁用黃app入口