舰导弹整合之春整合MyBatis框架配置事务的详细教程

  

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

  

1。在中修改代码如下:

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;豆类xmlns=" http://www.springframework.org/schema/beans "   xmlns: xsi=" http://www.w3.org/2001/XMLSchema-instance "   xmlns:上下文=" http://www.springframework.org/schema/context "   xmlns: aop=" http://www.springframework.org/schema/aop "   xmlns: tx=" http://www.springframework.org/schema/tx "   xsi: schemaLocation=" http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd   http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context.xsd   http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop.xsd   http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx.xsd”比;   & lt; !——开启注解的扫描,希望处理服务和刀,控制器不需要春天框架去处理——比;   & lt;上下文:component-scan基础包=癱om.txw”比;   & lt; !——配置哪些注解不扫描——比;   & lt;上下文:排他过滤器类型=白⑹汀?皁rg.springframework.stereotype表达式。控制器”/比;   & lt;/背景:component-scan>   & lt; !——春天整合MyBatis框架——比;   & lt; !——配置连接池——比;   & lt; bean id=笆菰础崩?癱om.mchange.v2.c3p0.ComboPooledDataSource”比;   & lt;属性名=" driverClass " value=" https://www.yisu.com/zixun/com.mysql.jdbc.Driver "/比;   & lt;属性名=" jdbcUrl " value=" https://www.yisu.com/zixun/jdbc mysql://ssm/比;   & lt;属性名="用户" value=" https://www.yisu.com/zixun/root "/比;   & lt;属性名="密码" value=" https://www.yisu.com/zixun/123456 "/比;   & lt;/bean>   & lt; !——配置SqlSessionFactory工厂——比;   & lt; bean id=皊qlSessionFactory”类=皁rg.mybatis.spring.SqlSessionFactoryBean”比;   & lt;属性名=笆菰础眗ef=笆菰础?比;   & lt;/bean>   & lt; !——配置AccountDao接口所在包——比;   & lt; bean id=癿apperScanner”类=皁rg.mybatis.spring.mapper.MapperScannerConfigurer”比;   & lt;属性名=" basePackage " value=" https://www.yisu.com/zixun/com.txw.dao "/比;   & lt;/bean>   春天& lt; !——配置框架声明式事务管理——比;   & lt; !——配置事务管理器——比;   & lt; bean id=皌ransactionManager”类=皁rg.springframework.jdbc.datasource.DataSourceTransactionManager”比;   & lt;属性名=笆菰础眗ef=笆菰础?比;   & lt;/bean>   & lt; !——配置事务通知——比;   & lt; tx:建议id=皌xAdvice事务管理器”=皌ransactionManager”比;   & lt; tx: attributes>   & lt; tx:方法名="找到*”只读=" true "/比;   & lt; tx:方法名==澳稀??”隔离比;   & lt;/tx: attributes>   & lt;/tx: advice>   & lt; !——配置AOP增强——比;   & lt; aop: config>   & lt; aop:顾问advice-ref=皌xAdvice切入点”=爸葱?* * ServiceImpl com.txw.service.impl。*(. .))”/比;   & lt;/aop: config>   & lt;/beans>      

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

        & lt; %——   由IntelliJ IDEA。   用户:阿黛尔   日期:0008年2020/7/8   时间:14:26   改变这个模板使用文件| |设置文件模板。   ——%比;   % @ & lt;页面contentType=" text/html; charset=utf - 8”语言=癹ava”%比;   & lt; html>   & lt; head>   & lt; title>首页& lt;/title>   & lt;/head>   & lt; body>   & lt; a href=" https://www.yisu.com/zixun/account/findAll " rel=巴獠縩ofollow”在测试查询& lt;/a>   & lt; h4>测试保存& lt;/h4>   & lt;形式行动=罢嘶?保存”方法=皃ost”比;   姓名:& lt; input type=" text " name="名称"/祝辞& lt; br/比;   金额:& lt; input type=" text " name="钱"/祝辞& lt; br/比;   & lt;输入类型="提交" value=" https://www.yisu.com/zixun/保存”/祝辞& lt; br/比;   & lt;/form>   & lt;/body>   & lt;/html>      

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

        包com.txw.controller;      进口com.txw.domain.Account;   进口com.txw.service.AccountService;   进口org.springframework.beans.factory.annotation.Autowired;   进口org.springframework.stereotype.Controller;   进口org.springframework.ui.Model;   进口org.springframework.web.bind.annotation.RequestMapping;   进口javax.servlet.http.HttpServletRequest;   进口javax.servlet.http.HttpServletResponse;   进口并不知道;/* *   *帐户的控制类   * @author阿戴尔   */@ controller   @RequestMapping(路径="/账户”)   @SuppressWarnings(“所有”)//注解警告信息   公开课AccountController {   @ autowired//自动类型注入   私人AccountService AccountService;   @RequestMapping (value=" https://www.yisu.com/findAll ")   公共字符串findAll(模型模型){   System.out.println(“表现层:查询所有账户…”);//调用findAll()方法   List

舰导弹整合之春整合MyBatis框架配置事务的详细教程