@GetMapping("/toCheckout") @Transactional public String toCheckout(HttpSession session, Model model) throws Exception { TUser user =(TUser) session.getAttribute(BookStoreConstants.USER_SESSION_KEY); Cart cart = (Cart)session.getAttribute(BookStoreConstants.CART_SESSION_KEY); TOrder tOrder = tOrderService.insertTOrder(cart, user); tOrderItemService.batchTOrderItems(cart,tOrder); Integer integer = tBookService.batchupdateBook(cart); tBookService.selectBookStoreById(cart); model.addAttribute("tOrderSquence",tOrder.getOrderSquence()); session.removeAttribute(BookStoreConstants.CART_SESSION_KEY); return "pages/cart/checkout"; }2.在主启动类上添加自动开启事务管理注解:@EnableTransactionManagement
@SpringBootApplication @MapperScan("com.atguigu.mapper") @EnableTransactionManagement public class SpringbootApplication { public static void main(String[] args) { SpringApplication.run(SpringbootBookstoreApplication.class, args); } }3.好了搞定!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)