当前位置: 首页 > 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.yayakq.cn/news/496973/

相关文章:

  • 网站知识介绍网站开发公司徐州
  • 手机网站作用海口企业网站建设
  • 北京网站设计有名 乐云践新做商城网站需要的功能
  • 做游戏网站用什么系统做建站公司的服务器
  • 注册网站会有哪些风险wordpress d8电影主题
  • 云建站网址经营网站需要什么费用
  • 多人在线协作网站开发项目网app
  • 淘宝联盟怎么自己做网站推广口碑营销的主要手段有哪些
  • 沈阳营销型网站制作技术快速seo优化
  • 加强网站队伍建设展厅设计费收费标准
  • 网站建设前端工具国外 网站 欣赏
  • 响应式外贸网站价格北京行业网站建设
  • 手机网站费用郑州网络推广哪家口碑好
  • 嘉兴公司网站模板建站小红书seo排名规则
  • 查数据的权威网站做电商没几个能赚钱的
  • 百度网站建设是什么意思wap网站建设兴田德润实惠
  • 深圳建设交易网站网站建设的步骤教程视频
  • 怎么查询网站是否被降权茶叶网站建设的优势
  • 自己切片做网站制作一个赚钱的网站
  • 婚恋网站的渠道网络建设WordPress问答插件路由
  • 网站内如何做论坛东莞网站建设相关技术
  • o2o手机网站建设技术wordpress重新打开多站点
  • 视频网站开发书籍云服务器建设网站用什么系统
  • 可以上传图片的公司网站wordpress 群站
  • 电气网站建设WordPress与odoo接口
  • wordpress网站好用吗电商网络销售是做什么
  • vs做网站怎么加文件夹辽宁建设工程信息网登录不上去
  • 企业企业网站建设广 做网站蓝光电影下载
  • 做网站是做完给钱还是庆阳手机网站设计
  • 建立网站编程重庆网站建设大概需要多少钱