当前位置: 首页 > news >正文

php免费网站模板最好的搜索引擎排名

php免费网站模板,最好的搜索引擎排名,php动态网站开发视频,个人网站备案 照片在java Spring5通过声明式事务(注解方式)完成一个简单的事务操作中 我们通过注解方式完成了一个事务操作 那么 下面 我还是讲一下 基于xml实现声明式事务的操作 其实在开发过程中 大家肯定都喜欢用注解 因为他方便 这篇文章中的xml方式 大家做个了解就好 还是 我们的这张表 记…

在java Spring5通过声明式事务(注解方式)完成一个简单的事务操作中 我们通过注解方式完成了一个事务操作
那么 下面 我还是讲一下 基于xml实现声明式事务的操作 其实在开发过程中 大家肯定都喜欢用注解 因为他方便
这篇文章中的xml方式 大家做个了解就好

还是 我们的这张表 记号他们的余额 然后 我们的项目环境还是延续之前的那个
在这里插入图片描述
如果没有看我之前文章的朋友 可以先去看一下 java Spring5 搭建操作数据库事务环境跟着 把项目环境搭建一下

然后 我们来到 senvice 下的 transfAccoSenvice类 修改代码如下

package senvice;import dao.transfAccoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class transfAccoSenvice {@Autowiredprivate transfAccoDao TransfAccoDao;//转账方法public void transferAccounts(int sponsorId, int recipientId, double money){Boolean paym = pay(money,sponsorId);if(paym){int i = 10/0;income(money,recipientId);System.out.println("交易完成");}}//支出方法public Boolean pay(double money,int userId) {String vacancies = CheckTheBalance(userId);double vacancie = Double.parseDouble(vacancies);if(money > vacancie) {System.out.println("余额不足");return false;}double settleAccounts = (vacancie - money);TransfAccoDao.updateMoney(String.valueOf(settleAccounts),userId);return true;}//收入方法public Boolean income(double money,int userId) {String vacancies = CheckTheBalance(userId);double vacancie = Double.parseDouble(vacancies);double settleAccounts = (vacancie + money);TransfAccoDao.updateMoney(String.valueOf(settleAccounts),userId);return true;}//查询指定用户余额public String CheckTheBalance(int userId){return TransfAccoDao.CheckTheBalance(userId);}
}

还是在transferAccounts中 用0做除数来模仿出一个异常

然后 我们 修改bean.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/tx http://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><!-- 数据库连接池 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"destroy-method="close"><property name="url" value="jdbc:mysql:///test" /><!--对应SQLyog里的数据库--><property name="username" value="root" />            <!-- 用户名 --><property name="password" value="root" />        <!-- 密码 --><property name="driverClassName" value="com.mysql.jdbc.Driver" /></bean><!-- JdbcTemplate对象 --><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><!--注入dataSource属性--><property name="dataSource" ref="dataSource"></property></bean><context:component-scan base-package="senvice"></context:component-scan><context:component-scan base-package="dao"></context:component-scan><!-->配置事务管理器--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref= "dataSource"></property></bean><!-- 配置通知 --><tx:advice id="txadvice"><tx:attributes><tx:method name="transfer*"/></tx:attributes></tx:advice><!-- 配置切入点和切面--><aop:config><aop:pointcut id="pt" expression="execution(* senvice.transfAccoSenvice.*(..))"/><aop:advisor  advice-ref="txadvice" pointcut-ref="pt"/></aop:config>
</beans>

关键的几行在于 tx:advic 配置通知 然后 tx:method中 name 我想让他指向的是 transferAccounts 就是我们模仿异常的那个方法 当然 你直接写 name=“transferAccounts” 自然是可以的 但我这个transfer* 表示 锁定所有 以transfer开头的 星号代表模糊搜索

然后 用aop:pointcut配合 切入点表达式 锁定了 senvice下的 transfAccoSenvice 中 所有的函数 *代表所有 (…)点方法参数

其他类 包括测试类 都不需要改
然后 我们打开测试类 运行代码如下
在这里插入图片描述
可以看到 我们这里 李四被减去200 打印出 11000 说明 第一段sql已经执行了 但因为事务 异常后应该回滚结果 所以李四的钱不会少 还是11200

我们到数据库中 刷新表并重新打开
在这里插入图片描述
可以看到 因为事务回滚 李四的钱并没有少
然后 我们到senvice 下的 transfAccoSenvice 将 int i = 10/0;干掉

然后运行测试类 结果如下
在这里插入图片描述
可以看到 没有异常的干涉 两端sql都执行成功了
那么 我们到数据库 刷新表 再重新打开
在这里插入图片描述
可以看到 没有异常 事务就正常提交了 我们的交易 也就正常完成啦

http://www.hkea.cn/news/368921/

相关文章:

  • 柳州建设局网站广告买卖网
  • 做外贸一般上哪些网站google play谷歌商店
  • 泉州手机网站制作如何做企业产品推广
  • 徐州手机网站设计汕头网站建设优化
  • 有没有专业收费做网站优化的百度百科优化排名
  • 常州网站建设哪家便宜江西seo推广软件
  • 如何用pageadmin做网站品牌宣传策略有哪些
  • 网站免费优化软件需要优化的地方
  • 24小时学会网站建设下载厦门百度竞价开户
  • 怎样学做网站网站权重等级
  • 做网站好还是做淘宝好北京seo推广
  • 郑州门户网站建设哪家好网站首页不收录
  • 网站制作营销型哪些网站可以发广告
  • 最新政府网站建设理念广州头条新闻最新
  • 济宁网站建设神华线上推广的三种方式
  • 我要表白网站在线制作如何做网站的教程
  • 福州论坛建站模板策划网络营销活动
  • 网站建设 天津百度市场应用官方app
  • 动态网站制作流程友情链接的定义
  • 企业网站开发方案免费建立一个网站
  • 网站引导页面制作的四个任务名称推广引流的10个渠道
  • 南宁网站建设制作后台网站关键词优化价格
  • 微信小程序商城制作公司宁波seo推广服务
  • 响应式购物网站公司seo是什么意思
  • 360未经证实的网站如何做电商运营方案
  • 网站建设类公司排名营销方案范文100例
  • 郑州网站设计 郑州网站开发网络优化有前途吗
  • 黑河做网站首页关键词排名优化
  • 网站二级域名怎么解析公司网络搭建
  • wordpress做网店win10优化大师是官方的吗