SSM框架中使用Spring的@Transactional注解进行事务管理(详细说明)

安卓开发者必看:Win11最新Fastboot驱动安装避坑指南(含Android Bootloader Interface选择技巧) 本文为安卓开发者提供了Windows 11系统下Fastboot驱动安装的详细指南,特别针对Android Bootloader Interface选择技巧和多设备并发连接时的驱动冲突问题。通过解析Windows 11的特殊驱动验证机制,推荐使用Google官方USB驱动,并提供安装流程、版本选择建议及疑难问题排查方法,帮助开发者高效完成开发环境配置。 阅读详情

原创出处:http://983836259.blog.51cto.com/7311475/1835807


原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://983836259.blog.51cto.com/7311475/1835807

一 介绍

在企业级应用中,保护数据的完整性是非常重要的一件事。因此不管应用的性能是多么的高、界面是多么的好看,如果在转账的过程中出现了意外导致用户的账号金额发生错误,那么这样的应用程序也是不可接受的

数据库的事务管理可以有效地保护数据的完整性(PS:关于数据库的事务管理基础可以参考我以前写过的这篇文章:http://www.zifangsky.cn/385.html),但是原生态的事务操作需要写不少的代码,无疑是非常麻烦的。在使用了Spring框架的应用中,我们可以使用@Transactional 注解方便地进行事务操作,如事务的回滚等。接下来我将以SSM框架中的事务注解操作进行举例说明:

二 测试项目的搭建

(1)项目结构和用到的jar包:

wKiom1eof0fANUsXAABpfvICtXQ778.png  wKioL1eof1HC3X_FAABJ5ENuWeA002.png

(2)测试使用到的SQL文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SET  FOREIGN_KEY_CHECKS=0;
 
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP  TABLE  IF EXISTS ` user `;
CREATE  TABLE  ` user ` (
  `id`  int (11)  NOT  NULL  AUTO_INCREMENT,
  ` name `  varchar (32)  DEFAULT  NULL ,
  ` password `  varchar (64)  DEFAULT  NULL ,
  `email`  varchar (64)  DEFAULT  NULL ,
  `birthday`  date  DEFAULT  NULL ,
  `money`  decimal (15,2)  DEFAULT  NULL ,
   PRIMARY  KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4  DEFAULT  CHARSET=utf8;
 
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT  INTO  ` user `  VALUES  ( '1' ,  'admin' ,  '123456' ,  'admin@qq.com' ,  '2000-01-02' ,  '1000.00' );
INSERT  INTO  ` user `  VALUES  ( '2' ,  'test' ,  '1234' ,  'test@zifangsky.cn' ,  '1990-12-12' ,  '2500.00' );
INSERT  INTO  ` user `  VALUES  ( '3' ,  'xxxx' ,  'xx' ,  'xx@zifangsky.cn' ,  '1723-06-21' ,  '4000.00' );

(3)使用mybatis-generator结合Ant脚本快速自动生成Model、Mapper等文件:

关于这方面可以参考我以前写过的一篇文章,这里就不多说了,传送门:http://www.zifangsky.cn/431.html

(4)一些基础配置文件:

i)web.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
< web-app  xmlns = "http://xmlns.jcp.org/xml/ns/javaee"
          xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
          version = "3.1" >
 
    < context-param >
        < param-name >contextConfigLocation</ param-name >
        < param-value >
            classpath:context/context.xml
        </ param-value >
    </ context-param >
     
    < listener >
        < listener-class >org.springframework.web.context.ContextLoaderListener</ listener-class >
    </ listener >
    < listener >
        < listener-class >org.springframework.web.context.request.RequestContextListener</ listener-class >
    </ listener >
     
    < servlet >
        < servlet-name >springmvc</ servlet-name >
        < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class >
        < init-param >
            < param-name >contextConfigLocation</ param-name >
            < param-value >classpath:context/jsp-dispatcher.xml</ param-value >
        </ init-param >
        < load-on-startup >1</ load-on-startup >
    </ servlet >
 
    < servlet-mapping >
        < servlet-name >springmvc</ servlet-name >
        < url-pattern >*.html</ url-pattern >
    </ servlet-mapping >
     
    < filter >
        < filter-name >characterEncodingFilter</ filter-name >
        < filter-class >org.springframework.web.filter.CharacterEncodingFilter</ filter-class >
        < init-param >
            < param-name >encoding</ param-name >
            < param-value >UTF-8</ param-value >
        </ init-param >
    </ filter >
    < filter-mapping >
        < filter-name >characterEncodingFilter</ filter-name >
        < url-pattern >/*</ url-pattern >
    </ filter-mapping >
 
</ web-app >

ii)jdbc配置文件jdbc.properties:

1
2
3
4
5
master.jdbc.driverClassName=com.mysql.jdbc.Driver
master.jdbc.url=jdbc:mysql://127.0.0.1:3306/transaction
#user
master.jdbc.username=root
master.jdbc.password=root

iii)context.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<? xml  version = "1.0"  encoding = "UTF-8" ?>
< beans  xmlns = "http://www.springframework.org/schema/beans"
     xmlns:cache = "http://www.springframework.org/schema/cache"
     xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"  xmlns:jee = "http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
            http://www.springframework.org/schema/jee 
            http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-4.0.xsd
            http://www.springframework.org/schema/cache  
             http://www.springframework.org/schema/cache/spring-cache-4.0.xsd  
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"
     xmlns:context = "http://www.springframework.org/schema/context"  xmlns:tx = "http://www.springframework.org/schema/tx"
     xmlns:aop = "http://www.springframework.org/schema/aop" >
 
    < context:component-scan  base-package = "cn.zifangsky.dao"
         annotation-config = "true"  />
    < context:component-scan  base-package = "cn.zifangsky.manager"
         annotation-config = "true"  />
 
    < bean  id = "propertyConfigurer"
         class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        < property  name = "locations" >
            < list >
                < value >classpath:jdbc.properties</ value >
            </ list >
        </ property >
    </ bean >
 
     <!-- 配置数据源 -->
    < bean  id = "dataSource"  class = "com.mchange.v2.c3p0.ComboPooledDataSource"
         destroy-method = "close" >
 
        < property  name = "driverClass" >
            < value >${master.jdbc.driverClassName}</ value >
        </ property >
        < property  name = "jdbcUrl" >
            < value >${master.jdbc.url}</ value >
        </ property >
        < property  name = "user" >
            < value >${master.jdbc.username}</ value >
        </ property >
        < property  name = "password" >
            < value >${master.jdbc.password}</ value >
        </ property >
         <!--连接池中保留的最小连接数。 -->
        < property  name = "minPoolSize" >
            < value >5</ value >
        </ property >
         <!--连接池中保留的最大连接数。Default: 15 -->
        < property  name = "maxPoolSize" >
            < value >30</ value >
        </ property >
         <!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
        < property  name = "initialPoolSize" >
            < value >10</ value >
        </ property >
         <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
        < property  name = "maxIdleTime" >
            < value >60</ value >
        </ property >
         <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
        < property  name = "acquireIncrement" >
            < value >5</ value >
        </ property >
         <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个 connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。 
             如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
        < property  name = "maxStatements" >
            < value >0</ value >
        </ property >
         <!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
        < property  name = "idleConnectionTestPeriod" >
            < value >60</ value >
        </ property >
         <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
        < property  name = "acquireRetryAttempts" >
            < value >30</ value >
        </ property >
         <!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用 getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试 
             获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
        < property  name = "breakAfterAcquireFailure" >
            < value >true</ value >
        </ property >
         <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议 使用idleConnectionTestPeriod或automaticTestTable 
             等方法来提升连接测试的性能。Default: false -->
        < property  name = "testConnectionOnCheckout" >
            < value >false</ value >
        </ property >
    </ bean >
 
     <!-- SqlMap setup for iBATIS Database Layer -->
    < bean  id = "sqlSessionFactory"  class = "org.mybatis.spring.SqlSessionFactoryBean" >
        < property  name = "configLocation"  value = "classpath:context/sql-map-config.xml"  />
        < property  name = "dataSource"  ref = "dataSource"  />
    </ bean >
    < bean  class = "org.mybatis.spring.mapper.MapperScannerConfigurer" >
        < property  name = "basePackage"  value = "cn.zifangsky.mapper"  />
        < property  name = "sqlSessionFactoryBeanName"  value = "sqlSessionFactory"  />
    </ bean >
 
    < bean  id = "sqlSessionTemplate"  class = "org.mybatis.spring.SqlSessionTemplate" >
        < constructor-arg  index = "0"  ref = "sqlSessionFactory"  />
    </ bean >
 
     <!-- Transaction manager for a single JDBC DataSource -->
    < bean  id = "transactionManager"
         class = "org.springframework.jdbc.datasource.DataSourceTransactionManager" >
        < property  name = "dataSource"  ref = "dataSource"  />
    </ bean >
     <!-- 开启注解方式声明事务 -->
    < tx:annotation-driven  transaction-manager = "transactionManager"  />
 
</ beans >

在上面的配置中,使用了C3P0作为数据库连接池,同时定义了自动扫描注解,Mybatis相关配置以及申明式事务管理,如果对这些基础不太熟的话可以参考下我以前写过的一些文章

iv)jsp-dispatcher.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<? 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:cache = "http://www.springframework.org/schema/cache"
     xmlns:mvc = "http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-4.0.xsd
       http://www.springframework.org/schema/cache  
       http://www.springframework.org/schema/cache/spring-cache-4.0.xsd  
       http://www.springframework.org/schema/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"
     default-lazy-init = "true" >
 
    < mvc:annotation-driven  />
 
    < context:annotation-config  />   <!-- 激活Bean中定义的注解 -->
 
     <!-- 启动自动扫描该包下所有的Bean(例如@Controller) -->
    < context:component-scan  base-package = "cn.zifangsky.controller"
         annotation-config = "true"  />
 
     <!-- 定义视图解析器 -->
    < bean
         class = "org.springframework.web.servlet.view.InternalResourceViewResolver" >
        < property  name = "prefix" >
            < value >/WEB-INF/jsp/</ value >
        </ property >
        < property  name = "suffix" >
            < value >.jsp</ value >
        </ property >
    </ bean >
 
</ beans >

v)sql-map-config.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<? xml  version = "1.0"  encoding = "UTF-8"  ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
< configuration >
    < settings >
         <!-- 全局的映射器启用或禁用缓存。 -->
        < setting  name = "cacheEnabled"  value = "true"  />
         <!-- 全局启用或禁用延迟加载 -->
        < setting  name = "lazyLoadingEnabled"  value = "true"  />
         <!-- 允许或不允许多种结果集从一个单独的语句中返回 -->
        < setting  name = "multipleResultSetsEnabled"  value = "true"  />
         <!-- 使用列标签代替列名 -->
        < setting  name = "useColumnLabel"  value = "true"  />
         <!-- 允许JDBC支持生成的键 -->
        < setting  name = "useGeneratedKeys"  value = "false"  />
         <!-- 配置默认的执行器 -->
        < setting  name = "defaultExecutorType"  value = "SIMPLE"  />
         <!-- 设置超时时间 -->
        < setting  name = "defaultStatementTimeout"  value = "25000"  />
    </ settings >
    < mappers >
        < mapper  resource = "sqlmaps/UserMapper.xml"  />
         
    </ mappers >
</ configuration >

(5)测试搭建的项目环境:

i)在UserManager.java接口中添加几个基本的接口:

1
2
3
4
5
6
7
8
9
10
11
12
13
public  interface  UserManager {
     int  deleteByPrimaryKey(Integer id);
 
     int  insert(User record);
 
     int  insertSelective(User record);
 
    User selectByPrimaryKey(Integer id);
 
     int  updateByPrimaryKeySelective(User record);
 
     int  updateByPrimaryKey(User record);
}

ii)UserManagerImpl.java:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package  cn.zifangsky.manager.impl;
 
import  java.math.BigDecimal;
 
import  javax.annotation.Resource;
 
import  org.apache.ibatis.jdbc.RuntimeSqlException;
import  org.springframework.stereotype.Service;
import  org.springframework.transaction.annotation.Transactional;
 
import  cn.zifangsky.manager.UserManager;
import  cn.zifangsky.mapper.UserMapper;
import  cn.zifangsky.model.User;
 
@Service (value= "userManagerImpl" )
public  class  UserManagerImpl  implements  UserManager{
     @Resource (name= "userMapper" )
     private  UserMapper userMapper;
         
     public  int  deleteByPrimaryKey(Integer id) {
         return  0 ;
    }
 
     public  int  insert(User record) {
         return  0 ;
    }
 
     public  int  insertSelective(User record) {
         return  0 ;
    }
 
     public  User selectByPrimaryKey(Integer id) {       
         return  userMapper.selectByPrimaryKey(id);
    }
 
     public  int  updateByPrimaryKeySelective(User record) {
         return  0 ;
    }
 
     public  int  updateByPrimaryKey(User record) {
         return  0 ;
    }
}

iii)UserController.java:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package  cn.zifangsky.controller;
 
import  java.math.BigDecimal;
 
import  javax.annotation.Resource;
 
import  org.springframework.stereotype.Controller;
import  org.springframework.web.bind.annotation.RequestMapping;
import  org.springframework.web.bind.annotation.RequestParam;
 
import  cn.zifangsky.manager.UserManager;
import  cn.zifangsky.model.User;
 
@Controller
public  class  UserController {
     @Resource (name =  "userManagerImpl" )
     private  UserManager userManager;
 
     @RequestMapping (value =  "/select" )
     public  String user( @RequestParam (name =  "userId" , required =  false ) Integer userId) {
        User user = userManager.selectByPrimaryKey(userId);
 
        System.out.println( "用户名: "  + user.getName());
        System.out.println( "邮箱: "  + user.getEmail());
 
         return  "success" ;
    }
 
}

iv)启动项目并进行测试:

项目启动后访问:http://localhost:8090/TransactionDemo/select.html?userId=2 ,如果发现控制台中输出如下则说明测试环境已经搭建成功了:

1
2
用户名: test
邮箱: test@zifangsky.cn

三 使用@Transactional注解管理事务示例

(1)在UserManager接口中添加一个如下方法:

1
2
3
4
5
6
7
8
9
10
11
/**
      * 转账
      * 
      * @param sourceAccountId
      *            源账户
      * @param targetAccountId
      *            目标账户
      * @param amount
      *            转账金额
      */
     void  transferMoney(Integer sourceAccountId, Integer targetAccountId, BigDecimal amount);

此方法目的是为了模拟转账操作

(2)在UserManagerImpl实现类中添加对用的实现方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Transactional (rollbackFor=Exception. class )
     public  void  transferMoney(Integer sourceAccountId, Integer targetAccountId, BigDecimal amount) {
        User sourceAccount = userMapper.selectByPrimaryKey(sourceAccountId);
        User targetAccount = userMapper.selectByPrimaryKey(targetAccountId);
         
        BigDecimal sourceMoney = sourceAccount.getMoney();
        BigDecimal targetMoney = targetAccount.getMoney();
         
         //判断账户余额是否足够
         if (sourceMoney.compareTo(amount) >  0 ){
            sourceAccount.setMoney(sourceMoney.subtract(amount));
            targetAccount.setMoney(targetMoney.add(amount));
             //更新数据库
            userMapper.updateByPrimaryKeySelective(sourceAccount);
             throw  new  RuntimeSqlException( "手动模拟转账时出现异常" );
//          userMapper.updateByPrimaryKeySelective(targetAccount);
     
        }
    }

可以看出,在这个方法上面申明了一个@Transactional,表明这个方法将要进行事务管理,同时需要说明的是rollbackFor参数定义了在出现了什么异常时进行事务的回滚,显然这里定义的就是所有的Exception都要进行事务回滚。与之相反的一个参数是norollbackFor,这里就不多说了。对于@Transactional注解我们不仅可以在一个方法上放置,而且可以在类上进行申明。如果在类级别上使用该注解,那么类中的所有公共方法都被事务化,否则就只有使用了@Transactional注解的公共方法才被事务化

在这个方法中为了模拟转账出现异常,因此在第一个账户进行更新后就手动抛出了一个异常

(3)在UserController类中添加一个模拟转账的方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@RequestMapping (value =  "/transfer" )
     public  String transfer( @RequestParam (name =  "account1" ) Integer account1,
             @RequestParam (name =  "account2" ) Integer account2,  @RequestParam (name =  "amount" ) Long amount) {
        System.out.println( "转账之前:" );
        System.out.println( "账户一的资金:"  + userManager.selectByPrimaryKey(account1).getMoney().longValue());
        System.out.println( "账户二的资金:"  + userManager.selectByPrimaryKey(account2).getMoney().longValue());
 
         // 转账
        userManager.transferMoney(account1, account2, BigDecimal.valueOf(amount));
 
        System.out.println( "转账之后:" );
        System.out.println( "账户一的资金:"  + userManager.selectByPrimaryKey(account1).getMoney().longValue());
        System.out.println( "账户二的资金:"  + userManager.selectByPrimaryKey(account2).getMoney().longValue());
 
         return  "success" ;
    }

(4)效果测试:

项目运行后访问:http://localhost:8090/TransactionDemo/transfer.html?account1=1&account2=2&amount=500

可以发现项目会进行保存,这时我们查看数据库中看看账户1和账户2中的金额有没有发生变化:

wKiom1eogGmhMeldAAA2j8nBafU212.png

可以看出,两者的金额都没有发生改变,说明事物的确进行了回滚。当然,有兴趣的同学可以把UserManagerImpl中那个 @Transactional  注解给去掉看看数据库中的这个金额在执行“转账”后又会不会发生改变?


本文出自 “zifangsky的个人博客” 博客,请务必保留此出处http://983836259.blog.51cto.com/7311475/1835807


WPT无线电能传输公式推导、编程计算、仿真验证全过程 主要分为5大模块,分别为无补偿,SS,SP,PP,PS,每个模块对应有公式推导,matlab编程计算相关参数以及将计算参数和仿真验证观察是否对应。采用matlab编程计算参数以及simulink仿真验证 阅读详情

相关推荐

[附源码]计算机毕业设计JAVA网上花店系统

附源码]计算机毕业设计JAVA网上花店系统项目运行环境配置:(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。项目技术:等等组成,B/S模式 + Maven管理等等。环境需要1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;3.tomcat。

ssm毕设程序设计 2445

SSM框架中使用Spring的@Transactional注解进行事务管理

一 介绍在企业级应用中,保护数据的完整性是非常重要的一件事。因此不管应用的性能是多么的高、界面是多么的好看,如果在转账的过程中出现了意外导致用户的账号金额发生错误,那么这样的应用程序也是不可接受的数据库的事务管理可以有效地保护数据的完整性(PS:关于数据库的事务管理基础可以参考我以前写过的这篇文章:http://www.zifangsky.cn/385.html),但是原生态...

weixin_34244102的博客 1398

ShardingSphere-jdbc 5.5.0 + spring boot 基础配置 - 实战篇

shardingsphere 5.5.0移除了sm4算法,自己加上即可。增加spi扩展org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm增加以下代码:SM4算法代码/***/static {@Getter@Overrideif (!

qq_21903999的博客 4745

SSM整合之注解方式(含事务管理)详细教程

SSM整合之注解方式(含事务管理)详细教程

majingbobo的博客 1708

手把手入门YOLO到改进优化教程 | 【P2基础篇】数据标注+环境搭建+模型训练

本节以 YOLO自定义目标检测训练为主线,带你从零开始完成 数据标注 → 环境搭建 → 模型训练 → 结果的流程。使用labelImg制作符合YOLO格式的自定义数据集。在Windows基于 Python + Conda 创建独立虚拟环境,安装 PyTorch + CUDA + ultralytics,配置 PyCharm 运行环境。本节不仅使用自定义数据集进行演示,同时也用公开数据集训练 YOLO,查看训练日志与可视化结果(PR、P/R/F1 曲线等)等。

嵌入式阿齐Archie 2万+

使用n8n搭建服务器监控系统:从Webhook到Telegram告警的完整实现

本文介绍基于n8n工作流平台搭建轻量级服务器监控系统的完整方案,通过Webhook接收监控数据、Token认证、阈值检查和Telegram告警推送,实现7x24小时自动化监控。整个系统由7个可视化节点组成,支持CPU、内存、磁盘、网络流量等多维度指标监控,告警阈值可灵活配置。相比传统的Prometheus或Zabbix方案,配置更简单、资源消耗更低,适合1-50台中小规模服务器的监控需求。实测表明从部署到上线仅需30分钟,告警响应延迟小于1秒,完全满足生产环境要求。

todoitbo的博客 1万+

SSM框架——以注解形式实现事务管理,回滚数据库操作

配置mybatis的事务管理,实现开发中,事务是必不可少的。本篇作为对上一篇的补充,说明在SSM框架中如何使用注解的形式进行事务管理。 什么是事务?           在编写业务的过程中,会需要进行事务处理,当需要执行多条插入语句时,如果前几条成功,而最后一条失败,那么我们需要回滚数据库操作,保持数据的一致性和完整性,此时,就需要利用DB的事务处理。事务是恢复和并发控制的

如果没有_明天 1万+

Xilinx系FPGA学习笔记(三)Vivado的仿真及ILA使用

接着学习vivado的使用方法。

贾saisai的博客 2546

SSM中常见的注解整理

将各种组件交由spring管理**@Controller:**控制层**@Service:**业务层**@Repository:**数据访问层@Controller、@Service、@Repository都可以称为@Component都用于类上。

m0_48895748的博客 1304

Superpowers与 OpenSpec、Spec Kit 对比

按照官方仓库定义,Superpowers 是一套构建在 composable skills 之上的完整软件开发工作流。它不是单纯的 prompt 集合,而是把一系列工程动作做成默认流程。一个需要明确的点:Superpowers 并不只偏 Claude Code,根据。

人不风流枉少年 1813

华为OD机试双机位C卷-热点网站统计 (Py/Java/C/C++/Js/Go)

华为OD机试双机位C卷 热点网站统计,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。 华为od机考真题 - 热点网站统计。

qq_45776114的博客 779

【SSM注解汇总】

MyBatis、Spring、SpringMVC中所使用的注解汇总

独上高楼,望尽天涯路。 1575

C++ (week6、7):Linux系统编程4:网络

Linux网络:计算机网络概述、TCP协议、Socket编程、IO多路复用机制(select、epoll)、HTTP协议、进程池、线程池、大文件网络传输问题

Edward2022的博客 1431

SSM框架配置避坑指南:当Spring MVC遇上MyBatis注解开发

本文深入解析SSM框架(Spring+Spring MVC+MyBatis)在注解开发模式下的常见配置问题与解决方案。从注解与XML混用冲突、@ControllerAdvice异常处理、@Transactional事务失效场景,到MyBatis性能优化和IDEA调试技巧,提供全面的避坑指南和最佳实践,帮助Java开发者高效构建企业级应用。

pz890123的博客 958

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

关于在SSM中使用注解的方式进行事务管理

关于在SSM中使用注解的方式进行事务管理的个人总结

最好人的博客 1588

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

SSM框架——以注解形式实现事务管理

上一篇博文《SSM三大框架整合详细教程》详细说了如何整合spring、SpringMVC和MyBatis这三大框架。但是没有说到如何配置mybatis的事务管理,实现开发中,事务是必不可少的。本篇作为对上一篇的补充,说明在SSM框架中如何使用注解的形式进行事务管理。 什么是事务?           在编写业务的过程中,会需要进行事务处理,当需要执行多条插入语句时,如果前几条成功,而最

justdoit_potato的博客 371

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

@Transactional注解的使用

我们在Java开发中,一般在service层的方法上,使用@Transactional注解,表示方法内的所有子操作是一个整体,要么全部成功,要么全部失败。

casually的博客 1010

详解ssm框架事务管理

毫无疑问ssm框架是现在企业最流行的一套框架,而在实际开发中事务管理的作用不可或缺,什么是事务?举一个简单的例子,张三转账100块钱给李四,在这个转账过程中,实际上分为两步,第一步是张三的账户减去100块钱,第二步是李四的账户增加100块钱,那么这两步就是一个事务,要么都成功,要么都失败,不能张三的账户少了100块钱而李四的账户没有加上100块钱。 既然说到事务管理,相信大家对事务的概念和ssm...

学无止境! 4901

SSM 配置及使用@Transactional 详解

SSM也就是常用的Spring + Spring MVC + Mybatis 框架 有时候一个方法涉及到多个表的操作,为了保证安全性,可靠性,得用事务,保证几条sql语句,要么全成功,要么回滚。 本篇博客先讲配置和使用,然后再讲具体的一些原理 一、首先配置事务管理类 在Spring的配置文件—applicant.xml(spring.xml) <bean id="txManager...

香烟达人的博客 1183

SSM框架-事务管理

1.什么是事务?.事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消。也就是事务具有原子性,一个事务中的一系列的操作要么全部成功,要么一个都不做。.事务的结束有两种,当事务中的所以步骤全部成功执行时,事务提交。如果其中一个步骤失败,将发生回滚操作,撤消撤消之前到事务开始时的所以操作。2.事务的四大特性1)    原子型 (一个事务中的多个操作要么都成功...

w_m_5的博客 1179

SSM框架整合——事务管理

事务管理实例体验: A-B转账:A减去100元,将这100元加到B账户上,这里需要两条update语句,如果在两条update语句出现了一些错误,那么对于先执行的A来说是不公平的。所以就有了事务ACID特性 事务ACID特性: 一、原子性: 事务开始不会停留在中间,要么恢复到之前未执行事务的状态,要么在执行完事务的状态。 二、一致性: 数据库是有一个正确的状态到另一个正确的状态,不应该出现不符合常理和业务的状态。 三、隔离性: 两个相同的事务或者多个事务并发操作数据库时,应该隔离每一个事务间的影响。 四、持

JoshRong的博客 1170

13、SSM框架-Spring 使用注解方式配置声明式事务(13)

一、概述         事务管理对于企业应用来说是至关重要的,即使出现异常情况,它也可以保证数据的一致性。spring Framework对事务管理提供了一致的抽象,其特点如下:为不同的事务API提供一致的编程模型,比如JTA(JavaTransaction API), JDBC, hibernate, JPA(Java Persistence API和JDO(Java Data Ob

gywtzh0889的专栏 2527

ssm 单独使用@Transactional声明式事务管理

简单聊一聊ssm单独使用@Transactional(不配合AOP) 要使用@Transactional注解要先进行以下配置 在applicationContext.xml中(有的人关于mybatis的配置不是配在这个文件的,而是配在别的文件,再在applicationContext.xml中import进来),写上这一行 配置好后我们需要在需要进行事务管理的类(实现service接口的类,不建...

weixin_40208575的博客 423

@Transactional注解在ssm上面使用的方法

@Transactional使用在界面层或者服务层

m0_64589497的博客 321

初步理解@Transactional注解

  在SSM项目中,经常在业务层的类或者方法上看到@Transactional注解,只是知道这个注解的作用是进行事务管理,但是具体有哪些属性,在什么情况下进行回滚,确是不那么清楚。所以在网上看了一些视频和博客,初步理解了Spring的事务管理。这里记录的主要是一些概念,如果想要能快速学会使用和理解事务管理,建议去相关视频。我看的是https://www.imooc.com/learn/4...

weixin_30396699的博客 228
上一篇: SSM框架——以注解形式实现事务管理---简单说明
下一篇: 给上传的图片添加水印--在流文件中添加
异常的昵称
博客等级 码龄10年 18粉丝 17原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值