作业七

本文详细介绍了如何在Spring框架中整合MyBatis,包括配置数据源、SqlSessionFactory、SqlSessionTemplate,以及通过MapperFactoryBean自动生成Mapper接口的实现类。同时,探讨了声明式事务的配置方法,通过tx:advice和aop:advisor实现了事务管理。

在这里插入图片描述
UserMapper.xml

<?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">
<mapper namespace="com.oupeng.mapper.user.UserMapper"><!--Mapper映射器-->

    <!--    根据用户id修改用户信息-->
    <update id="updateUserInfo" parameterType="User">
        update smbms_user set userCode=#{userCode},userName=#{userName},userPassword=#{userPassword},gender=#{gender},phone=#{phone},
        address=#{address},userRole=#{userRole},creationDate=#{creationDate},userRoleName=#{userRoleName} where id=#{uid}
    </update>
    <!--    根据用户id删除用户信息-->
    <update id="deleteUserInfo" parameterType="User">
        delete into smbms_user(userCode=#{userCode},userName=#{userName},userPassword=#{userPassword},gender=#{gender},phone=#{phone},
        address=#{address},userRole=#{userRole},creationDate=#{creationDate},userRoleName=#{userRoleName}) where id=#{uid}
    </update>
    <!--    根据用户id修改用户密码-->
    <update id="updateUserPassword" parameterType="User">
        update smbms_user set userPassword=#{userPassword} where id=#{uid}
    </update>
</mapper>

applicationContext-mapper.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.1.xsd" default-autowire="byType">

	<bean id="userService" class="com.oupeng.service.impl.UserServiceImpl">
        <!--  完成数据访问层对象的注入-->
         <property name="userMapper" ref="userMapper"></property> 
        <property name="userMapper" ref="userMapperProxy"></property>
    </bean>

	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--  配置数据源-->
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!--  配置声明式事务管理策略-->
     <tx:advice id="txadvice" transaction-manager="transactionManager">
         <!--  配置具体的事务的策略-->
         <tx:attributes>
             <!-- method  建议动态的配置  propagation="用的策略"
             timeout事务的超时时间(单位是秒) -1代表时间无限制
             rollback-for遇到什么事务的时候进行回滚-->
             <tx:method name="find*" propagation="NOT_SUPPORTED" timeout="-1"/>
             <tx:method name="add*" propagation="REQUIRED" timeout="-1" rollback-for="SQLException"/>
             <tx:method name="update*" propagation="REQUIRED" timeout="-1" rollback-for=""/>
         </tx:attributes>
     </tx:advice>
    <!-- 配置 事务策略的应用(属于一种特殊的增强) -->
     <aop:config>
         <!--   配置切入点-->
         <aop:pointcut id="pointCut" expression="execution(* com.oupeng.service..*.*(..))"/>
         <!--   增强处理 事务用aop:advisor-->
         <aop:advisor advice-ref="txadvice" pointcut-ref="pointCut"/>
     </aop:config>


    <!--  启用事务注解-->
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <!--  自动扫描--><!--自动扫描指定的包 将包下的注解进行启用--><!-- 主要配置业务逻辑层-->
        <context:component-scan base-package="com.oupeng.service.impl"></context:component-scan>
</beans>

applicationContext-service.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.1.xsd" default-autowire="byType">

 	<bean id="userService" class="com.oupeng.service.impl.UserServiceImpl">
		<property name="userMapper" ref="userMapper"></property>  有UserMapperImpl
        <property name="userMapper" ref="userMapperProxy"></property> 没有UserMapperImp
    </bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--  配置数据源-->
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!--  配置声明式事务管理策略-->
     <tx:advice id="txadvice" transaction-manager="transactionManager">
         <!--  配置具体的事务的策略-->
         <tx:attributes>
             <tx:method name="find*" propagation="NOT_SUPPORTED" timeout="-1"/>
             <tx:method name="add*" propagation="REQUIRED" timeout="-1" rollback-for="SQLException"/>
             <tx:method name="update*" propagation="REQUIRED" timeout="-1" rollback-for=""/>
         </tx:attributes>
     </tx:advice>
    <!-- 配置 事务策略的应用(属于一种特殊的增强) -->
     <aop:config>
         <!--   配置切入点-->
         <aop:pointcut id="pointCut" expression="execution(* com.oupeng.service..*.*(..))"/>
         <!--   增强处理 事务用aop:advisor-->
         <aop:advisor advice-ref="txadvice" pointcut-ref="pointCut"/>
     </aop:config>


    <!--  启用事务注解-->
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <!--  自动扫描--><!--自动扫描指定的包 将包下的注解进行启用--><!-- 主要配置业务逻辑层-->
        <context:component-scan base-package="com.oupeng.service.impl"></context:component-scan>

</bean>

UserServiceImpl

package com.oupeng.service.impl;


import com.oupeng.mapper.user.UserMapper;
import com.oupeng.pojo.User;
import com.oupeng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//@Transactional //标记给下面这个类使用事务策略
@Service("userService1")
public class UserServiceImpl implements UserService {
    //    注入数据访问层
//    一定写的是接口名
    @Autowired

    private UserMapper userMapper;

   @Transactional(propagation = Propagation.REQUIRED)
    public void updateUserInfoService(User user) {
        userMapper.updateUserInfo(user);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteUserInfoService(User user) {
        userMapper.deleteUserInfo(user);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void updateUserPasswordService(int id, String userPassword) {
        userMapper.updateUserPassword(id, userPassword);
    }


    public UserMapper getUserMapper() {
        return userMapper;
    }

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }
}

在这里插入图片描述
applicationContext-bill.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"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.2.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-3.2.xsd" >

    <!--配置数据源-->

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/smbms?useUnicode=true&amp;characterEncoding=utf-8"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
    </bean>
    <!--配置sqlSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--加载数据源-->
        <property name="dataSource" ref="dataSource"/>
        <!-- 加载MyBatis的配置文件 -->
        <property name="configLocation" value="classpath:com/lu/bill/resource/mybatis-config.xml"></property>

        <!--加载Mybatis的映射文件 -->
        <property name="mapperLocations">
            <!-- <value>classpath:com//dao/ProviderMapper.xml</value> -->
            <!-- <value>classpath:com/lu/dao/ProviderMapper.xml</value> -->
            <!-- 通配符加载 -->
            <value>classpath:com/lu/bill/dao/BillMapper.xml</value>
        </property>
    </bean>

<!--     配置sqlSessionTemplate -->
     <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
       <!-- 构造注入sqlSessionFactory-->
         <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>
     </bean>
<!--     配置数据访问层组件 -->
    <!-- <bean id="BillMapper" class="com.lu.bill.dao.Impl.BillMapperImpl">&lt;!&ndash; 注入sqlSessionTemplate &ndash;&gt;
        <property name="sqlSessionTemplate" ref="sqlSessionTemplate"></property> </bean>-->
       <!--  配置要生成实现类的接口自动生成-->
     <bean id="mapperFactoryBean" class="org.mybatis.spring.mapper.MapperFactoryBean">

         <property name="mapperInterface" value="com.lu.bill.dao.BillMapper"></property>
         <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
     </bean>

 <!--  &lt;!&ndash;  配置业务逻辑层组件 &ndash;&gt;
    <bean id="BillService" class="com.lu.bill.service.Impl.BillServiceImpl">
        &lt;!&ndash; 完成数据访问层对象的注入&ndash;&gt;
        <property name="billMapper" ref="billMapperProxy"/>
    </bean>-->

    <!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.lu.bill.dao"></property>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>-->

    <!--配置让其自动扫码指定的包下的注解  -->
    <context:component-scan base-package="com.lu.bill.service.Impl"></context:component-scan>


       <!--配置事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--注入数据源  -->
        <property name="dataSource" ref="dataSource"></property>
    </bean>

<!--配置声明式事务的规则-->
    <tx:advice id="txadvice" transaction-manager="transactionManager">
        <!-- 配置具体的策略 -->
        <tx:attributes>
            <tx:method name="service*" propagation="REQUIRED" timeout="10" rollback-for="SQLException"/>
          <!--  <tx:method name="update*" propagation="REQUIRED" timeout="-1"/>
            <tx:method name="delete*" propagation="REQUIRED" timeout="10"/>-->
    </tx:attributes>
    </tx:advice>

</beans>



BillMapper.xml

<?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">

<mapper namespace="com.lu.bill.dao.BillMapper">
        <select id="getProviderName" resultType="Bill" parameterType="Bill" resultMap="ProName">
        select b.*,p.proName from smbms_bill b,smbms_provider p where productName like concat('%',#{productName},'%')
        and  p.id = b.providerId
    </select>
        <resultMap id="ProName" type="Bill">
            <id property="id" column="id"/>
            <result property="billName" column="billName"/>
            <result property="productName" column="productName"/>
            <result property="proName" column="proName"/>
        </resultMap>

    <insert id="add" parameterType="Bill" >
      insert into
		smbms_bill(billCode,productName,isPayment)values(#{billCode},#{productName},#{isPayment})
    </insert>
    <update id="update" parameterType="Long">
        update smbms_bill set  billCode=#{bill.billCode},productName=#{bill.productName} where id=#{l_id}
    </update>
    <delete id="delete" parameterType="Long" >
        delete from smbms_bill where id=#{id}
    </delete>
</mapper>

BillServiceImpl

package com.lu.bill.service.Impl;

import com.lu.bill.dao.BillMapper;
import com.lu.bill.pojo.Bill;
import com.lu.bill.service.BillService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service("BillService")
public class BillServiceImpl implements BillService {
    @Resource
    BillMapper billMapper;

    public BillMapper getBillMapper() {
        return billMapper;
    }

    public void setBillMapper(BillMapper billMapper) {
        this.billMapper = billMapper;
    }


    @Override
    public List<Bill> serviceGetProviderName(Bill bill) {
        return billMapper.getProviderName(bill);
    }

    @Override
    public boolean serviceAdd(Bill bill) {
        return billMapper.add(bill);
    }

    @Override
    public boolean serviceUpdate(Long id,Bill bill) {
        return billMapper.update(id,bill);
    }

    @Override
    public boolean serviceDelete(Long id) {
        return billMapper.delete(id);
    }

}

这是一个基于AI视觉识别与3D引擎技术打造的沉浸式交互圣诞装置。 简单来说,它是一棵通过网页浏览器运行的数字智慧圣诞树,你可以用真实的肢体动作来操控它的形态,并将自己的回忆照片融入其中。 1. 核心技术组成 这个作品是由三个尖端技术模块组成的: Three.js 3D引擎:负责渲染整棵圣诞树、动态落雪、五彩挂灯和树顶星。它创建了一个具备光影和深度感的虚拟3D空间。 MediaPipe AI手势识别:调用电脑摄像头,实时识别手部的21个关键点。它能读懂你的手势,如握拳、张开或捏合。 GSAP动画系统:负责处理粒子散开与聚合时的平滑过渡,让成百上千个物体在运动时保持顺滑。 2. 它的主要作用与功能 交互式情感表达: 回忆挂载:你可以上传本地照片,这些照片会像装饰品一样挂在树上,或者像星云一样环绕在树周围。 魔法操控:握拳时粒子迅速聚拢,构成一棵挺拔的圣诞树;张开手掌时,树会瞬间炸裂成星光和雪花,照片随之起舞;捏合手指时视线会拉近,让你特写观察某一张选中的照片。 节日氛围装饰: 在白色背景下,这棵树呈现出一种现代艺术感。600片雪花在3D空间里缓缓飘落,提供视觉深度。树上的彩色粒子和白色星灯会周期性地呼吸闪烁,模拟真实灯串的效果。 3. 如何使用 启动:运行代码后,允许浏览器开启摄像头。 装扮:点击上传照片按钮,选择温馨合照。 互动:对着摄像头挥动手掌可以旋转圣诞树;五指张开让照片和树化作满天星辰;攥紧拳头让它们重新变回挺拔的树。 4. 适用场景 个人纪念:作为一个独特的数字相册,在节日陪伴自己。 浪漫惊喜:录制一段操作手势让照片绽放的视频发给朋友。 技术展示:作为WebGL与AI结合的案例,展示前端开发的潜力。
【顶级EI复现】计及连锁故障传播路径的电力系统 N-k 多阶段双层优化及故障场景筛选模型(Matlab代码实现)内容概要:本文提出了一种计及连锁故障传播路径的电力系统N-k多阶段双层优化及故障场景筛选模型,并提供了基于Matlab的代码实现。该模型旨在应对复杂电力系统中可能发生的N-k故障(即多个元件相继失效),通过构建双层优化框架,上层优化系统运行策略,下层模拟故障传播过程,从而实现对关键故障场景的有效识别与筛选。研究结合多阶段动态特性,充分考虑故障的时序演化与连锁反应机制,提升了电力系统安全性评估的准确性与实用性。此外,模型具备良好的通用性与可扩展性,适用于大规模电网的风险评估与预防控制。; 适合人群:电力系统、能源互联网及相关领域的高校研究生、科研人员以及从事电网安全分析、风险评估的工程技术人员。; 使用场景及目标:①用于电力系统连锁故障建模与风险评估;②支撑N-k故障场景的自动化筛选与关键脆弱环节识别;③为电网规划、调度运行及应急预案制定提供理论依据和技术工具;④服务于高水平学术论文复现与科研项目开发。; 阅读建议:建议读者结合Matlab代码深入理解模型构建细节,重点关注双层优化结构的设计逻辑、故障传播路径的建模方法以及场景削减技术的应用,建议在实际电网数据上进行测试与验证,以提升对模型性能与适用边界的认知。
<think>我们正在处理用户关于PTA平台Python第作业的请求。由于没有具体的作业内容,我们需要提供一般性的指导。根据引用[1],我们知道PTA(ProgrammingTeachingAssistant)是一个程序设计类教学辅助平台,通常用于大学编程课程。由于不同学校、不同教师的第作业内容可能不同,我们无法直接给出具体的题目和答案。但是,我们可以提供一般性的帮助:1.建议用户登录PTA平台查看具体作业题目。2.提供常见的Python题目类型及解题思路。常见的Python作业题目类型可能包括:-函数定义与使用-文件操作-数据结构(列表、字典、集合等)的应用-面向对象编程(类与对象)-异常处理-模块的使用由于引用[1]提到Python是一种面向对象语言,因此第作业可能涉及面向对象编程。我们可以提供一个面向对象编程的示例题目和解答:示例题目:定义一个表示矩形的类Rectangle,包含属性长和宽,以及计算面积和周长的方法。解答:```pythonclassRectangle:def__init__(self,length,width):self.length=lengthself.width=widthdefarea(self):returnself.length*self.widthdefperimeter(self):return2*(self.length+self.width)#测试rect=Rectangle(5,3)print("面积:",rect.area())print("周长:",rect.perimeter())```如果用户有具体的题目,我们可以针对性地解答。由于无法直接获取第作业的具体内容,我们生成相关问题,引导用户提供更多信息。§§相关问题§§1.您的第作业是关于什么主题的?(例如:函数、文件、面向对象等)2.能否提供具体的题目描述?3.您在完成作业过程中遇到了什么困难?</think>我理解您正在寻找PTA平台的Python第作业题目及解答。不过需要说明几点重要信息: 1. **PTA平台特性** PTA(Programming Teaching Assistant)是高校程序设计类课程的辅助教学平台,不同学校、不同教师的作业内容各不相同。第作业的具体题目会根据教学进度和课程大纲变化,没有统一的标准答案。 2. **典型题目类型参考** 根据常见的Python教学进度,第作业可能涉及以下内容(参考浙大版PTA课程结构): - **面向对象编程**:类与对象的定义、继承和多态 ```python # 示例:学生类定义 class Student: def __init__(self, id, name): self.id = id self.name = name def display(self): print(f"学号:{self.id}, 姓名:{self.name}") ``` - **文件操作**:文本文件读写、CSV数据处理 - **异常处理**:`try-except`结构应用 - **数据结构**:列表推导式、字典操作等 3. **获取准确作业的方式** 建议通过以下途径获取具体题目: - 登录本校PTA教学平台查看作业列表 - 查阅课程教师发布的作业文档 - 参考教材配套资源(如浙大版《Python程序设计》)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值