ssm整合之Spring整合MyBatis框架配置事务的详细教程

这篇文章主要介绍了ssm整合之Spring整合MyBatis框架配置事务,本文通过图文实例代码相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

ssm整合之Spring整合MyBatis框架配置事务

1.在applicationContext.xml修改代码如下:

           

2.修改index.jsp的代码如下:

 <%-- Created by IntelliJ IDEA. User: Adair Date: 2020/7/8 0008 Time: 14:26 To change this template use File | Settings | File Templates. --%><%@ page contentType="text/html;charset=UTF-8" language="java" %>  首页 

测试保存

姓名:
金额:

3.修改帐户的控制类的代码如下:

 package com.txw.controller; import com.txw.domain.Account; import com.txw.service.AccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; /** *帐户的控制类 * @author Adair */ @Controller @RequestMapping(path = "/account") @SuppressWarnings("all")   // 注解警告信息 public class AccountController { @Autowired // 自动类型注入 private AccountService accountService; @RequestMapping(value = "/findAll") public String findAll(Model model){ System.out.println("表现层:查询所有账户..."); // 调用findAll()方法 List list = accountService.findAll(); // 进行存储 model.addAttribute("list",list); return "list"; } /** * 保存 * @return */ @RequestMapping("/save") public void save(Account account, HttpServletRequest request, HttpServletResponse response) throws Exception { accountService.saveAccount(account); response.sendRedirect(request.getContextPath()+"/account/findAll"); return; } }

4.重新部署项目,运行如图所示:

在这里插入图片描述

5.通过浏览器访问http://localhost:8080/如图所示:

在这里插入图片描述

6.填写姓名和金额如图所示:

在这里插入图片描述

7.点击保存会跳转到如图所示的界面:

在这里插入图片描述

8.控制台打印结果如图所示:

在这里插入图片描述

以上就是ssm整合之Spring整合MyBatis框架配置事务的详细教程的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Java