智慧屏 安装 app如何提升家庭娱乐与教育体验的关键工具
512
2023-03-22
ssm整合之Spring整合MyBatis框架配置事务的详细教程
ssm整合之Spring整合MyBatis框架配置事务
1.在applicationContext.xml修改代码如下:
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context" xmlns:aop="http://springframework.org/schema/aop" xmlns:tx="http://springframework.org/schema/tx" xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop.xsd http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx.xsd">
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:context="http://springframework.org/schema/context"
xmlns:aop="http://springframework.org/schema/aop"
xmlns:tx="http://springframework.org/schema/tx"
xsi:schemaLocation="http://springframework.org/schema/beans
http://springframework.org/schema/beans/spring-beans.xsd
http://springframework.org/schema/context
http://springframework.org/schema/context/spring-context.xsd
http://springframework.org/schema/aop
http://springframework.org/schema/aop/spring-aop.xsd
http://springframework.org/schema/tx
http://springframework.org/schema/tx/spring-tx.xsd">
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") //http:// 注解警告信息
public class AccountController {
@Autowired // 自动类型注入
private AccountService accountService;
@RequestMapping(value = "/findAll")
public String findAll(Model model){
System.out.println("表现层:查询所有账户...");
// 调用findAll()方法
List
// 进行存储
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.控制台打印结果如图所示:
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~