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

vs进行网站建设百度推广竞价是什么意思

vs进行网站建设,百度推广竞价是什么意思,设计一个产品,建设手机网站价格系列文章目录 Spring中事务的处理相关内容的学习 文章目录系列文章目录前言一、Spring事务简介二、案例:银行账户转账1.题目要求和思路分析2.实现步骤3.实现结构三、spring事务角色四、spring事务相关配置五、案例:转账业务追加日志1.题目要求和思路分析…

系列文章目录

Spring中事务的处理相关内容的学习


文章目录

  • 系列文章目录
  • 前言
  • 一、Spring事务简介
  • 二、案例:银行账户转账
    • 1.题目要求和思路分析
    • 2.实现步骤
    • 3.实现结构
  • 三、spring事务角色
  • 四、spring事务相关配置
  • 五、案例:转账业务追加日志
    • 1.题目要求和思路分析
    • 2.解决方案和代码实现
  • 总结


前言


一、Spring事务简介

在这里插入图片描述

二、案例:银行账户转账

1.题目要求和思路分析

在这里插入图片描述

2.实现步骤

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

3.实现结构

项目结构
在这里插入图片描述

JdbcConfig

package org.example.config;import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;import javax.sql.DataSource;public class JdbcConfig {@Value("${jdbc.driver}")private String drive;@Value("${jdbc.url}")private String url;@Value("${jdbc.username}")private String username;@Value("${jdbc.password}")private String password;@Beanpublic DataSource dataSource(){DruidDataSource ds=new DruidDataSource();ds.setDriverClassName(drive);ds.setUrl(url);ds.setUsername(username);ds.setPassword(password);return ds;}//配置事务管理器@Beanpublic PlatformTransactionManager transactionManager(DataSource dataSource){DataSourceTransactionManager transactionManager=new DataSourceTransactionManager();transactionManager.setDataSource(dataSource);return transactionManager;}
}

MybatisConfig

package org.example.config;import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;import javax.sql.DataSource;public class MybatisConfig {//定义bean,SqlSessionFactoryBean,用于产生SqlSessionFactory对象@Beanpublic SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){SqlSessionFactoryBean ssfb=new SqlSessionFactoryBean();ssfb.setTypeAliasesPackage("org.example.domain");ssfb.setDataSource(dataSource);return ssfb;}//定义bean,返回MapperScannerConfigurer对象@Beanpublic MapperScannerConfigurer mapperScannerConfigurer(){MapperScannerConfigurer msc=new MapperScannerConfigurer();msc.setBasePackage("org.example.dao");return msc;}
}

SpringConfig

package org.example.config;import org.springframework.context.annotation.*;
import org.springframework.transaction.annotation.EnableTransactionManagement;@Configuration
@ComponentScan("org.example")
@PropertySource("classpath:jdbc.properties")
@Import({JdbcConfig.class,MybatisConfig.class})
@EnableTransactionManagement
public class SpringConfig {
}

AccountDao

package org.example.dao;import org.apache.ibatis.annotations.*;
import org.example.domain.Account;import java.util.List;public interface AccountDao {@Update("update tbl_account set money = money + #{money} where name = #{name}")void inMoney(@Param("name") String name, @Param("money") Double money);@Update("update tbl_account set money = money - #{money} where name = #{name}")void outMoney(@Param("name") String name, @Param("money") Double money);
}

Account

package org.example.domain;public class Account {private Integer id;private String name;private Double money;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Double getMoney() {return money;}public void setMoney(Double money) {this.money = money;}@Overridepublic String toString() {return "Account{" +"id=" + id +", name='" + name + '\'' +", money=" + money +'}';}
}

AccountService

package org.example.service;import org.springframework.transaction.annotation.Transactional;public interface AccountService {/*** 转账操作* @param out 转出方* @param in 转入方* @param money 金额*///开启事务@Transactionalpublic void transfer(String out,String in,Double money);
}

AccountServiceImpl

package org.example.service.impl;import org.example.dao.AccountDao;
import org.example.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class AccountServiceImpl implements AccountService {@Autowiredprivate AccountDao accountDao;public void transfer(String out, String in, Double money) {accountDao.outMoney(out,money);int i=10/0;accountDao.inMoney(in,money);}
}

AccountServiceTest

package org.example.service;import org.example.config.SpringConfig;
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(classes = SpringConfig.class)
public class AccountServiceTest {@Autowiredprivate AccountService accountService;@Testpublic void testTransfer() throws Exception{accountService.transfer("Tom","Jerry",100.0);}
}

jdbc.properties

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring_db?useSSL=false
jdbc.username=root
jdbc.password=****

三、spring事务角色

在这里插入图片描述
在这里插入图片描述

四、spring事务相关配置

在这里插入图片描述

有些异常是默认不参加回滚的。只有运行时异常和Error的错误spring会自动回滚,其他异常是不参加回滚,所以要设置事务回滚异常

五、案例:转账业务追加日志

1.题目要求和思路分析

在这里插入图片描述

2.解决方案和代码实现

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

项目结构
在这里插入图片描述
LogDao

package org.example.dao;import org.apache.ibatis.annotations.Insert;public interface LogDao {@Insert("insert into tbl_log (info,createDate) values(#{info},now()) ")void log(String info);
}

LogService

package org.example.service;import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;public interface LogService {@Transactional(propagation = Propagation.REQUIRES_NEW)void log(String out,String in,Double money);
}

LogServiceImpl

package org.example.service.impl;import org.example.dao.LogDao;
import org.example.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class LogServiceImpl implements LogService {@Autowiredprivate LogDao logDao;public void log(String out, String in, Double money) {logDao.log("转账操作由"+out+"到"+in+",金额:"+money);}
}

AccountServiceImpl

package org.example.service.impl;import org.example.dao.AccountDao;
import org.example.service.AccountService;
import org.example.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class AccountServiceImpl implements AccountService {@Autowiredprivate AccountDao accountDao;@Autowiredprivate LogService logService;public void transfer(String out, String in, Double money) {try {accountDao.outMoney(out,money);accountDao.inMoney(in,money);}finally {logService.log(out,in,money);}}
}

其余代码按照上面银行转账的操作进行编写,须注意数据库要新建tbl_log的表。


总结

本节主要讲了spring中对于事务的处理,并分析事务管理的一些小案例
参考视频

http://www.hotlads.com/news/4068.html

相关文章:

  • 建立网站后台谷歌优化方法
  • 网站的优势与不足企业qq一年多少费用
  • 南通网站建设优化公司外链推广论坛
  • z-blog跟wordpress很像无忧seo博客
  • 网站建设模板研究seo优化技术培训中心
  • 有哪些做任务的网站平台网站建设推广服务
  • 网站怎么做搜索关键词优化外包服务
  • 无人机东莞网站建设制作网站要花多少钱
  • 聊城做网站的公司教程分享几个x站好用的关键词
  • 西安网站建设招聘seo的作用主要有
  • 装饰公司怎么做微网站手机优化游戏性能的软件
  • 多多返利网站建设程序百度seo公司哪家最好
  • 在国外建设网站百度电商平台app
  • 沈阳做网站 智域长沙seo网络优化
  • 广州做网站 信科网络最佳磁力吧cili8
  • 国内做设计的网站有哪些网络服务提供者知道或者应当知道
  • 网站建设公司发展方向及趋势关键词优化公司排行
  • 网站建设与管理实践心得台州seo服务
  • 网站百度推广和优化谷歌seo 优化
  • 珠江摩尔网站建设建站公司
  • 网站建设开发报告郑州百度推广代理公司
  • 网站开发策划百度权重网站排名
  • 做淘客必须有自己内部网站吗焊工培训技术学校
  • wordpress类似的前端上海百度提升优化
  • 网站图怎么做会高清图片网站的推广方案的内容有哪些
  • 什么是网站版面布局企业自助建站
  • 公司营销外包seo资料
  • 做淘宝客的的网站有什么要求企业网络搭建
  • 网站建设要哪些人?网络舆情监测中心
  • 那家网站做照片书好环球网疫情最新