设为首页 加入收藏

TOP

Sping aop 以及Spring aop 的应用事务管理(五)
2023-08-26 21:11:04 】 浏览:93
Tags:Sping aop 以及 Spring 应用事 管理
t;1.18.28</version> </dependency> </dependencies>

(2)spring配置文件

<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--springmvc的配置-->
    <context:component-scan base-package="com.ddd"/>



    <!--spring整合mybatis的配置-->

    <!--数据源-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
          <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
          <!--mysql驱动为8.0以后必须使用时区-->
          <property name="url" value="jdbc:mysql://localhost:3306/aaa?serverTimezone=Asia/Shanghai"/>
          <property name="username" value="root"/>
          <property name="password" value="root"/>
    </bean>

    <!--spring封装了一个类SqlSessionFactoryBean类,可以把mybatis中的配置-->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
          <property name="dataSource" ref="dataSource"/>
          <property name="mapperLocations" value="classpath:/mapper/*.xml"/>
    </bean>

    <!--为指定dao包下的接口生产代理实现类-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sessionFactory"/>
        <!--它会为com.ykq.dao包下的所有接口生产代理实现类-->
        <property name="basePackage" value="com.ddd.dao"/>
    </bean>

<!----================以下内容是关于事务的配置===================------>
    <!--事务切面管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--开启事务管理注解的驱动-->
    <tx:annotation-driven/>
</beans>

(3) dao类和xml

public interface UserDao {
    //1.修改账号余额
    public void updateBalance(@Param("id") int id, @Param("money") double money);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace必须和dao接口的名称一模一样-->
<mapper namespace="com.ddd.dao
首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇详谈 springboot整合shiro 下一篇SpringBoot3集成ElasticSearch

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目