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

淘宝网站的建设目的网络营销推广外包平台

淘宝网站的建设目的,网络营销推广外包平台,东莞塘厦招聘网最新招聘,山东省住房城乡建设厅网站首页系列文章目录 Spring中事务的处理相关内容的学习 文章目录系列文章目录前言一、Spring事务简介二、案例#xff1a;银行账户转账1.题目要求和思路分析2.实现步骤3.实现结构三、spring事务角色四、spring事务相关配置五、案例#xff1a;转账业务追加日志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 dsnew DruidDataSource();ds.setDriverClassName(drive);ds.setUrl(url);ds.setUsername(username);ds.setPassword(password);return ds;}//配置事务管理器Beanpublic PlatformTransactionManager transactionManager(DataSource dataSource){DataSourceTransactionManager transactionManagernew 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 {//定义beanSqlSessionFactoryBean用于产生SqlSessionFactory对象Beanpublic SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){SqlSessionFactoryBean ssfbnew SqlSessionFactoryBean();ssfb.setTypeAliasesPackage(org.example.domain);ssfb.setDataSource(dataSource);return ssfb;}//定义bean返回MapperScannerConfigurer对象Beanpublic MapperScannerConfigurer mapperScannerConfigurer(){MapperScannerConfigurer mscnew 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 i10/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.drivercom.mysql.cj.jdbc.Driver jdbc.urljdbc:mysql://localhost:3306/spring_db?useSSLfalse jdbc.usernameroot 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.hkea.cn/news/14403289/

相关文章:

  • 专业官方网站建设phpstudy怎么做网站
  • 怎样写网站文案查询关键词网站
  • 电商网站建设常见问题网站建设 紧急检查工作
  • 制作一个自适应网站源码本地网站搭建
  • 培训行业网站建设求职简历模板2021
  • 网站运营方案设计网站的建设思路
  • 平价建网站格公众号的网站怎么做的
  • 长春联通网站备案小广告怎么做
  • 刚做的网站关键字能搜到么qq个人邮箱登录入口
  • 建立公司网站步骤wordpress轮播插件下载
  • 自己建立网站怎么建福田蒙派克4s店电话和地址
  • wordpress搬站换空间wordpress邮件发布
  • 免费网站空间 - 百度wordpress常用插件汇总 知更鸟
  • 区块链网站用vue.js做怎么样移动宽带怎么网上续费
  • 做企业网站制作郑佩佩 最新消息
  • 网课网站桂阳县网站建设公司哪家好
  • 旅游网站建设主要工作手机响应式网站开发模板之家
  • 网站建设服务器主板1150针河南企业网络推广方法
  • 小程序同步wordpress佛山百度seo代理
  • 网站建设人群定位ds2600ii色带
  • 在线做图的网站一级消防工程师考试科目和题型
  • 如何制作网站的步骤潮州住房与建设局网站
  • 口碑好的网站设计制作价格郑州优化网站公司
  • 十几万 建设网站mvc做门户网站
  • 做个网站需要多少钱vi设计风格有哪些
  • zen cart 网站google plus保定哪个公司做网站好
  • 东莞网站建设基本流程网站建设案例精粹
  • 什么行业愿意做网站php网站挂马
  • 农村电商网站建设做淘宝客网站好搭建吗
  • 无锡做网站哪个公司好找承包工程的平台