ssm整合之Spring整合MyBatis框架配置事务
1.在applicationContext.xml修改代码如下:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://.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<Account> 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框架配置事务的文章就介绍到这了,更多相关Spring整合MyBatis配置事务内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!