看到一遍文章说controller可以加事务,特别测试了下,发现不行

文章内容

https://blog.csdn.net/mmm333zzz/article/details/45288061


附上测试代码

@Controller
@Transactional
public class DemoController2 {
	
 
	@Autowired
    private CustomerDao customerDao;
 

	@RequestMapping(value = "/demoController2/selectList.do")
	public void selectList(HttpServletResponse response,HttpServletRequest resquest){
		Customer customer=new Customer();
		customer.setApplicationNO("D00021807040005");
		customer.setId_card("11111");
		System.out.println("更新数据开始");
		customerDao.update(customer);
		System.out.println("更新数据结束");
		
	}
	
 
}

测试结果

2018-07-13 14:42:54,041 [http-bio-8080-exec-7] DEBUG [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
  2018-07-13 14:42:54,042 [http-bio-8080-exec-7] DEBUG [org.mybatis.spring.SqlSessionUtils] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7cc6f37a] was not registered for synchronization because synchronization is not active
  2018-07-13 14:42:54,044 [http-bio-8080-exec-7] DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
  2018-07-13 14:42:54,049 [http-bio-8080-exec-7] DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] - JDBC Connection [jdbc:mysql://127.0.0.1:3306/test_zhou?characterEncoding=UTF-8, UserName=root@localhost, MySQL-AB JDBC Driver] will not be managed by Spring
  2018-07-13 14:42:54,050 [http-bio-8080-exec-7] DEBUG [com.xxxx.core.dao.pushBusiness.CustomerDao.update] - ==>  Preparing: update ap_customer SET id_card=? where applicationNO=? 
  2018-07-13 14:42:54,051 [http-bio-8080-exec-7] DEBUG [com.xxxx.core.dao.pushBusiness.CustomerDao.update] - ==> Parameters: 11111(String), D00021807040005(String)
  2018-07-13 14:42:54,055 [http-bio-8080-exec-7] DEBUG [com.xxxx.core.dao.pushBusiness.CustomerDao.update] - <==    Updates: 1
  2018-07-13 14:42:54,055 [http-bio-8080-exec-7] DEBUG [org.mybatis.spring.SqlSessionUtils] - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7cc6f37a]
  2018-07-13 14:42:54,055 [http-bio-8080-exec-7] DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource


没有事务

转载于:https://www.cnblogs.com/feiZhou/p/9343993.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值