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

长沙网建站交换友情链接的渠道

长沙网建站,交换友情链接的渠道,网站设计和美工一样吗,拿网站的文章做外链场景模拟 参考基于注解的声明式事务 修改Spring的配置文件 将Spring配置文件中去掉tx:annotation-driven标签&#xff0c;并添加配置&#xff1a; <?xml version"1.0" encoding"UTF-8"?> <beans xmlns"http://www.springframework.org…

场景模拟

参考基于注解的声明式事务

修改Spring的配置文件

将Spring配置文件中去掉tx:annotation-driven标签,并添加配置:

<?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!--    开启组件扫描--><context:component-scan base-package="com.yogurt.spring6.xmltx"></context:component-scan><!--    数据源对象 引入外部属性文件,创建数据源对象--><context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder><bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="url" value="${jdbc.url}"></property><property name="driverClassName" value="${jdbc.driver}"></property><property name="username" value="${jdbc.user}"></property><property name="password" value="${jdbc.password}"></property></bean><!--    JdbcTemplate对象--><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="druidDataSource"></property></bean><!--    事务管理器--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="druidDataSource"></property></bean><!--    配置事务增强--><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="get*" read-only="true"/><tx:method name="update" read-only="false" propagation="REQUIRED"></tx:method><tx:method name="buy*" read-only="false" propagation="REQUIRED"></tx:method></tx:attributes></tx:advice><!--    配置切入点和通知使用的方法--><aop:config><aop:pointcut id="pt" expression="execution(* com.yogurt.spring6.xmltx.service.*.*(..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="pt"></aop:advisor></aop:config>
</beans>

Controller

@Controller
public class BookController {@Autowiredprivate BookService bookService;/*** 买书的方法* @param bookId* @param userId*/public void buyBook(Integer bookId,Integer userId){//调用Service方法bookService.buyBook(bookId,userId);}}

 Service

@Service
public class BookServiceImpl implements BookService {@Autowiredprivate BookDao bookDao;/*** 买书的方法* @param bookId* @param userId*/@Overridepublic void buyBook(Integer bookId, Integer userId) {//根据图书id查询图书价格Integer price = bookDao.getBookPriceByBookId(bookId);//更新图书库存量 -1bookDao.updateStock(bookId);//更新用户表用户余额 -图书价格bookDao.updateUserBalance(userId,price);}
}

Dao

@Repository
public class BookDaoImpl implements BookDao {@Autowiredprivate JdbcTemplate jdbcTemplate;/*** 根据id查询图书价格* @param bookId* @return*/@Overridepublic Integer getBookPriceByBookId(Integer bookId) {String sql = "select price from t_book where book_id = ?";Integer price = jdbcTemplate.queryForObject(sql, Integer.class, bookId);return price;}/*** 更新库存信息* @param bookId*/@Overridepublic void updateStock(Integer bookId) {String sql = "update t_book set stock = stock -1 where book_id = ?";jdbcTemplate.update(sql,bookId);}/*** 更新用户表用户余额 -图书价格* @param userId* @param price*/@Overridepublic void updateUserBalance(Integer userId, Integer price) {String sql = "update t_user set balance = balance - ? where user_id = ?";jdbcTemplate.update(sql,price,userId);}
}

 测试:

@SpringJUnitConfig(locations = "classpath:beans-xml.xml")
public class TestBookTx {@Autowiredprivate BookController bookController;@Testpublic void testBuyBook(){bookController.buyBook(1,1);}}

某些小细节:

http://www.ritt.cn/news/15889.html

相关文章:

  • 上海网站建设案例seoheuni
  • 做商城网站多少钱百度关键词查询工具
  • 广东营销型网站建设广东网站优化公司
  • 设计师网站导航青年帮百度百科官网首页
  • 免费网站湖南疫情最新消息今天
  • 网站备案要关闭吗站长工具查询seo
  • 阳江网站制作网络销售是干嘛的
  • 深圳网站维护页面设计模板网站建站哪家好
  • 做网站可以用新建项目的方式吗账户竞价托管费用
  • 西安SEO网站建设小红书关键词排名怎么做
  • 商城网站建设专业公司刷推广链接
  • asp网站怎么做404页面福州网站建设团队
  • 网站建设jw100高粱seo博客
  • 手机平台网站开发外链工厂 外链
  • 北京手机网站建设公司哪家好外贸营销系统
  • 晚上做设计挣钱的网站网络营销计划包括哪七个步骤
  • 巢湖网 网站网站建设推广多少钱
  • 免费网站seo软件网络推广app是干什么的
  • 北京企业建设网站制作广州网站优化费用
  • 网站交易模块怎么做成品短视频app源码的优点
  • 漳州最专业的网站建设公司做一个公司网页多少钱
  • 上海做兼职上哪个网站厦门seo
  • 北京做网站开发公司有哪些东莞网站建设工作
  • 网站设置5个关键词外贸找客户有什么网站
  • 网页制作的常用工具seo信息查询
  • 做网站 后端是谁来做的网站推广途径和推广要点有哪些?
  • 做食品那些网站专业做网站设计
  • 一个网店转让可以卖多少钱网站seo专员
  • 外贸商城网站模板交换链接是什么
  • 如果自己想建设网站该怎么做百度信息流广告位置