最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ssm整合之Spring整合MyBatis框架配置事務(wù)的詳細(xì)教程

 更新時(shí)間:2020年10月23日 09:18:52   作者:學(xué)無止路  
這篇文章主要介紹了ssm整合之Spring整合MyBatis框架配置事務(wù),本文通過圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

ssm整合之Spring整合MyBatis框架配置事務(wù)

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

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="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">
  <!--開啟注解的掃描,希望處理service和dao,controller不需要Spring框架去處理-->
  <context:component-scan base-package="com.txw">
    <!--配置哪些注解不掃描-->
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
  </context:component-scan>
  <!--Spring整合MyBatis框架-->
  <!--配置連接池-->
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl" value="jdbc:mysql:///ssm"/>
    <property name="user" value="root"/>
    <property name="password" value="123456"/>
  </bean>
  <!--配置SqlSessionFactory工廠-->
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
  </bean>
  <!--配置AccountDao接口所在包-->
  <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.txw.dao"/>
  </bean>
  <!--配置Spring框架聲明式事務(wù)管理-->
  <!--配置事務(wù)管理器-->
  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
  </bean>
  <!--配置事務(wù)通知-->
  <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
      <tx:method name="find*" read-only="true"/>
      <tx:method name="*" isolation="DEFAULT"/>
    </tx:attributes>
  </tx:advice>
  <!--配置AOP增強(qiáng)-->
  <aop:config>
    <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.txw.service.impl.*ServiceImpl.*(..))"/>
  </aop:config>
</beans>

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" %>
<html>
<head>
  <title>首頁(yè)</title>
</head>
<body>
  <a href="account/findAll" rel="external nofollow" >測(cè)試查詢</a>
  <h3>測(cè)試保存</h3>
  <form action="account/save" method="post">
     姓名:<input type="text" name="name" /><br/>
     金額:<input type="text" name="money" /><br/>
     <input type="submit" value="保存"/><br/>
  </form>
</body>
</html>

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 // 自動(dòng)類型注入
  private AccountService accountService;
  @RequestMapping(value = "/findAll")
  public String findAll(Model model){
    System.out.println("表現(xiàn)層:查詢所有賬戶...");
    // 調(diào)用findAll()方法
    List<Account> list = accountService.findAll();
    // 進(jìn)行存儲(chǔ)
    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.重新部署項(xiàng)目,運(yùn)行如圖所示:

在這里插入圖片描述

5.通過瀏覽器訪問http://localhost:8080/如圖所示:

在這里插入圖片描述

6.填寫姓名和金額如圖所示:

在這里插入圖片描述

7.點(diǎn)擊保存會(huì)跳轉(zhuǎn)到如圖所示的界面:

在這里插入圖片描述

8.控制臺(tái)打印結(jié)果如圖所示:

在這里插入圖片描述

到此這篇關(guān)于ssm整合之Spring整合MyBatis框架配置事務(wù)的文章就介紹到這了,更多相關(guān)Spring整合MyBatis配置事務(wù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java使用Sftp和Ftp實(shí)現(xiàn)對(duì)文件的上傳和下載

    Java使用Sftp和Ftp實(shí)現(xiàn)對(duì)文件的上傳和下載

    這篇文章主要介紹了Java使用Sftp和Ftp實(shí)現(xiàn)對(duì)文件的上傳和下載,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • SpringBoot配置多數(shù)據(jù)源的四種方式分享

    SpringBoot配置多數(shù)據(jù)源的四種方式分享

    在日常開發(fā)中我們都是以單個(gè)數(shù)據(jù)庫(kù)進(jìn)行開發(fā),在小型項(xiàng)目中是完全能夠滿足需求的,但是,當(dāng)我們牽扯到大型項(xiàng)目的時(shí)候,單個(gè)數(shù)據(jù)庫(kù)就難以承受用戶的CRUD操作,那么此時(shí),我們就需要使用多個(gè)數(shù)據(jù)源進(jìn)行讀寫分離的操作,本文就給大家介紹SpringBoot配置多數(shù)據(jù)源的方式
    2023-07-07
  • java并發(fā)高的情況下用ThreadLocalRandom來生成隨機(jī)數(shù)

    java并發(fā)高的情況下用ThreadLocalRandom來生成隨機(jī)數(shù)

    如果我們想要生成一個(gè)隨機(jī)數(shù),通常會(huì)使用Random類。但是在并發(fā)情況下Random生成隨機(jī)數(shù)的性能并不是很理想,本文主要介紹了java并發(fā)高的情況下用ThreadLocalRandom來生成隨機(jī)數(shù),感興趣的可以了解一下
    2022-05-05
  • java與微信小程序?qū)崿F(xiàn)websocket長(zhǎng)連接

    java與微信小程序?qū)崿F(xiàn)websocket長(zhǎng)連接

    這篇文章主要為大家詳細(xì)介紹了java與微信小程序?qū)崿F(xiàn)websocket長(zhǎng)連接,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • 實(shí)例講解JAVA 適配器模式

    實(shí)例講解JAVA 適配器模式

    這篇文章主要介紹了JAVA 適配器模式的的相關(guān)資料,文中示例代碼非常詳細(xì),供大家參考和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • java組件commons-fileupload實(shí)現(xiàn)文件上傳、下載、在線打開

    java組件commons-fileupload實(shí)現(xiàn)文件上傳、下載、在線打開

    這篇文章主要介紹了java組件commons-fileupload實(shí)現(xiàn)文件上傳、下載、在線打開,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • 詳細(xì)介紹Java函數(shù)式接口

    詳細(xì)介紹Java函數(shù)式接口

    函數(shù)式接口在Java中是指有且僅有一個(gè)抽象方法的接口。當(dāng)然接口中可以包含其他的方法默認(rèn)、靜態(tài)、私有,具體內(nèi)容請(qǐng)參考下面文章內(nèi)容
    2021-09-09
  • springboot指定profiles啟動(dòng)失敗問題及解決

    springboot指定profiles啟動(dòng)失敗問題及解決

    這篇文章主要介紹了springboot指定profiles啟動(dòng)失敗問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • SpringBoot中WEB的啟動(dòng)流程分析

    SpringBoot中WEB的啟動(dòng)流程分析

    今天我們就來分析下springboot啟動(dòng)web項(xiàng)目整個(gè)流程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2022-03-03
  • java數(shù)字和中文算數(shù)驗(yàn)證碼的實(shí)現(xiàn)

    java數(shù)字和中文算數(shù)驗(yàn)證碼的實(shí)現(xiàn)

    這篇文章主要介紹了java數(shù)字和中文算數(shù)驗(yàn)證碼的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07

最新評(píng)論

阿鲁科尔沁旗| 濮阳市| 阜南县| 元阳县| 鹿邑县| 梓潼县| 安塞县| 都安| 轮台县| 文山县| 张家川| 太和县| 华安县| 广平县| 佛学| 台东县| 景泰县| 中山市| 筠连县| 山东省| 德兴市| 木兰县| 旬邑县| 西华县| 咸阳市| 襄汾县| 独山县| 正宁县| 筠连县| 陇南市| 冀州市| 潮安县| 元阳县| 平罗县| 拜泉县| 民县| 莎车县| 游戏| 金秀| 德钦县| 合作市|