日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

Spring整合SpringMVC + Mybatis基礎框架的配置文件詳解

瀏覽:134日期:2023-11-26 10:34:54
前言

新建一個普通的Maven項目

基本目錄結構

├── src # │ ├── main # │ │└── java # java代碼目錄│ │└── resources # 配置文件目錄, 存放下面Spring配置文件│ ├── test # 單元測試目錄├── web # web目錄│ └── WEB-INF # web.xml 配置文件目錄1. Mybatis層編寫

1、在 resources 目錄下新建數據庫配置文件 database.properties

jdbc.driver=com.mysql.jdbc.Driver# 如果是使用 MySQL8.0+ 那么還需要增加一個時區的配置; serverTimezone=Asia/Shanghaijdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8jdbc.username=rootjdbc.password=123456

2、在 resources 目錄下創建Mybatis配置文件 mybatis-config.xml

<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE configuration PUBLIC '-//mybatis.org//DTD Config 3.0//EN' 'http://mybatis.org/dtd/mybatis-3-config.dtd'><configuration> <!--配置數據源, 交給Spring--> <!--配置log--> <settings> <!--STDOUT_LOGGING: 標準的日志工廠實現--> <setting name='logImpl' value='STDOUT_LOGGING'/> </settings> <!--配置別名--> <typeAliases> <package name='com.pro.pojo'/> </typeAliases> <!--綁定Mapper--> <mappers> <mapper /> </mappers></configuration>2. Spring層編寫

1. Spring整合Mybatis

配置Spring整合MyBatis,這里數據源使用c3p0連接池;

編寫Spring整合Mybatis的相關的配置文件;在 resources 目錄下創建 spring-dao.xml

注意:這里要引入上面Mybatis層的兩個配置文件,配置文件的名稱不要寫錯

<?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' 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'> <!--1. 關聯數據庫配置文件--> <context:property-placeholder location='classpath:database.properties'/> <!--2. 連接池 dbcp: 半自動化操作, 不能自動連接 c3p0: 自動化操作 (自動加載配置文件并設置到對象中) druid, hikari --> <bean class='com.mchange.v2.c3p0.ComboPooledDataSource'> <property name='driverClass' value='${jdbc.driver}'/> <property name='jdbcUrl' value='${jdbc.url}'/> <property name='user' value='${jdbc.username}'/> <property name='password' value='${jdbc.password}'/> <!--c3p0連接池的私有屬性, 最大最小連接池大小--> <property name='maxPoolSize' value='30'/> <property name='minPoolSize' value='10'/> <!--關閉連接后不自動commit--> <property name='autoCommitOnClose' value='false'/> <!--連接超時--> <property name='checkoutTimeout' value='10000'/> <!--獲取連接失敗重試次數--> <property name='acquireRetryAttempts' value='2'/> </bean> <!--3. sqlSessionFactory--> <bean class='org.mybatis.spring.SqlSessionFactoryBean'> <property name='dataSource' ref='dataSource'/> <!--綁定Mybatis配置文件--> <property name='configLocation' value='classpath:mybatis-config.xml'/> </bean> <!--4. 配置Dao掃描包, 動態實現Dao接口注入到Spring容器中--> <bean class='org.mybatis.spring.mapper.MapperScannerConfigurer'> <!--注入 sqlSessionFactory--> <property name='sqlSessionFactoryBeanName' value='sqlSessionFactory'/> <!--配置要掃描的dao包--> <property name='basePackage' value='com.pro.dao'/> </bean></beans>

2. Spring整合service

將業務層的類注入到Spring中,在 resources 目錄下創建 spring-service.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'> <!--1. 掃描service下的包--> <context:component-scan base-package='com.pro.service'/> <!--2. 將業務層的類注入到Spring中--> <bean class='com.pro.service.BooksServiceImpl'> <property name='booksMapper' ref='booksMapper'/> </bean> <!--3. 配置聲明式事務--> <bean class='org.springframework.jdbc.datasource.DataSourceTransactionManager'> <!--注入數據源--> <property name='dataSource' ref='dataSource'/> </bean> <!--4. 配置aop實現事務織入--> <!--配置事務通知--> <tx:advice transaction-manager='transactionManager'> <!--1. 給那些方法配置事務--> <!--2. 配置事務的傳播特性: propagation--> <tx:attributes> <tx:method name='*' propagation='REQUIRED'/> </tx:attributes> </tx:advice> <!--配置事務切入--> <aop:config> <!--mapper包下的所有類的所有方法--> <aop:pointcut expression='execution(* com.pro.dao.*.*(..))'/> <aop:advisor advice-ref='txAdvice' pointcut-ref='txPointCut'/> </aop:config></beans>3. SpringMVC層編寫

1. 編寫web.xml

修改 WEB-INF 下的 web.xml 文件

這里引入Spring整合的配置文件 applicationContext.xml

<?xml version='1.0' encoding='UTF-8'?><web-app xmlns='https://jakarta.ee/xml/ns/jakartaee' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd' version='5.0'> <!--DispatchServlet--> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!--加載Spring配置文件--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </init-param> <!--啟動級別--> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--亂碼過濾--> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--Session過期時間--> <session-config> <session-timeout>15</session-timeout> </session-config></web-app>

2. 編寫spring-mvc.xml

在 resources 目錄下創建 spring-mvc.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:mvc='http://www.springframework.org/schema/mvc' xmlns:context='http://www.springframework.org/schema/context' xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd'> <!--1. 注解驅動--> <mvc:annotation-driven/> <!--2. 靜態資源過濾--> <mvc:default-servlet-handler/> <!--3. 掃描包: controller--> <context:component-scan base-package='com.pro.controller'/> <!--4. 視圖解析器--> <bean class='org.springframework.web.servlet.view.InternalResourceViewResolver'> <property name='prefix' value='/WEB-INF/jsp/'/> <property name='suffix' value='.jsp'/> </bean></beans>4. Spring配置整合文件,applicationContext.xml

在 resources 目錄下創建 applicationContext.xml

這里引入上面三個配置文件 spring-dao.xml、spring-service.xml、spring-mvc.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' xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd'> <import resource='classpath:spring-dao.xml'/> <import resource='classpath:spring-service.xml'/> <import resource='classpath:spring-mvc.xml'/></beans>

依賴

<!--依賴--><dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> </dependency> <!--Junit--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13</version> </dependency> <!--數據庫驅動--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.47</version> </dependency> <!--數據庫連接池--> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> <!--Servlet - JSP --> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!--Mybatis--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.2</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>2.0.2</version> </dependency> <!--Spring--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.1.9.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>5.1.9.RELEASE</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.9.4</version> </dependency></dependencies><!--靜態資源導出問題--><build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources></build>

到此這篇關于Spring整合SpringMVC + Mybatis基礎框架的配置文件的文章就介紹到這了,更多相關Spring整合SpringMVC Mybatis內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
亚洲欧美日韩精品一区二区| 亚洲精品乱码久久久久久蜜桃麻豆 | 国产日本精品| 免费观看日韩电影| 在线一区二区三区视频| 亚洲视频国产| 日韩精品免费观看视频| 日韩不卡一区二区三区| 视频一区二区三区在线| 日本大胆欧美人术艺术动态| 中文字幕免费一区二区| 日韩国产在线不卡视频| 欧美一级网址| 亚洲性色视频| 香蕉久久夜色精品国产| 天堂va欧美ⅴa亚洲va一国产| 欧美日韩一区二区三区不卡视频| 欧美偷窥清纯综合图区| 国产精品传媒麻豆hd| 久久精品国产网站| 国产超碰精品| 亚洲免费一区二区| 亚洲va久久久噜噜噜久久| 久久国产麻豆精品| 国产成人在线中文字幕| 伊人久久高清| 9色国产精品| 日本一区二区三区中文字幕| 国产日韩欧美三级| 桃色一区二区| 一本一道久久a久久| 69堂免费精品视频在线播放| 精品深夜福利视频| 宅男在线一区| 四虎在线精品| 精品一区二区三区亚洲| 亚洲v在线看| 亚洲一区导航| 精品久久不卡| 在线视频亚洲| 麻豆免费精品视频| 亚洲精品网址| 97久久精品| 国产自产自拍视频在线观看| 亚洲欧美日韩国产| 国产精品99久久久久久董美香| 桃色一区二区| 91精品尤物| 久久久成人网| 青青草91视频| 91久久国产| 麻豆极品一区二区三区| 好吊一区二区三区| 国产伦一区二区三区| 日本精品在线中文字幕| 日本成人精品| 久久久成人网| 国产精品任我爽爆在线播放 | 国产精品极品国产中出| 久久国产日本精品| 欧美日韩一区二区三区四区在线观看| 日韩一区二区中文| 日韩中文字幕无砖| 国产v日韩v欧美v| 日韩综合小视频| 欧美一级精品| 精品资源在线| 亚洲综合婷婷| 久久精品不卡| 免费在线亚洲| 日韩一区精品字幕| 日韩影院二区| 欧美午夜三级| 人人精品人人爱| 都市激情国产精品| 日韩av一区二区三区| 成人av二区| 在线观看精品| 国产情侣一区| 亚洲精品护士| 91成人超碰| 免费观看亚洲| 国产精品麻豆成人av电影艾秋| 99热精品在线观看| 中文字幕在线官网| 国产精品羞羞答答在线观看| 国产亚洲毛片在线| 老司机精品视频网| 日本综合精品一区| 欧洲毛片在线视频免费观看| 成人在线免费观看网站| 国产精品一区二区精品 | av一区二区高清| 久草免费在线视频| 国产精品久久久久久久久久久久久久久| 麻豆精品网站| 欧美+日本+国产+在线a∨观看| 精品国产91| 国产亚洲精品美女久久| 亚洲欧洲国产精品一区| 亚洲一区二区三区四区五区午夜 | 天堂va蜜桃一区二区三区| 欧美成a人免费观看久久| 久久免费福利| 国产精品一区二区中文字幕| 日韩av一区二区三区| 亚久久调教视频| 水蜜桃久久夜色精品一区的特点| 1000部精品久久久久久久久| 欧美精品高清| 日韩成人亚洲| 色偷偷色偷偷色偷偷在线视频| 精品免费av| 国产精品xvideos88| 欧美亚洲人成在线| 欧美日韩黄网站| 国产精品亚洲一区二区在线观看| 国产精品视频一区二区三区| 国产美女精品视频免费播放软件| 日韩高清不卡一区| 日韩黄色av| 日韩不卡手机在线v区| 日本伊人久久| 91大神在线观看线路一区| 久久国产尿小便嘘嘘| 国产精品一区三区在线观看| 国产精品久久久免费| 欧美极品中文字幕| 国产精品久久久一区二区| 久久影视三级福利片| 国产成人免费精品| 中文一区一区三区高中清不卡免费| 91欧美国产| 麻豆精品蜜桃| 国产精品呻吟| 亚洲91在线| 国产精品男女| 精品深夜福利视频| 少妇久久久久| 一本一道久久a久久精品蜜桃| 影音先锋国产精品| 伊人精品久久| 国产精品香蕉| 欧美国产极品| 97精品国产福利一区二区三区| 樱桃视频成人在线观看| 久久中文字幕二区| 免播放器亚洲| 91午夜精品| 91欧美日韩| 性欧美长视频| 欧美日韩午夜电影网| 日韩av片子| 免费毛片在线不卡| 亚洲乱码一区| 麻豆久久一区二区| av在线日韩| 日韩精品一二三四| 国产精品一区二区精品视频观看 | 国产欧美视频在线| 国产精品伦理久久久久久| 国产字幕视频一区二区| 国产一区二区精品| 久久国产欧美日韩精品| 成午夜精品一区二区三区软件| 久久在线免费| 日韩在线观看中文字幕| 久久91视频| 久久精品影视| 日韩中文字幕| 亚洲精品福利电影| 中文字幕日本一区| 国产福利91精品一区二区| 一区免费视频| 久久国产人妖系列| 久久婷婷亚洲| 国产亚洲一区二区三区啪| 日韩在线第七页| 亚洲精品一区二区在线播放∴| 久久天堂影院| 国产精品日韩| 国产一区二区三区亚洲| 一区二区视频欧美| 91成人在线| 婷婷精品进入| 国产精品欧美大片| 免费日韩av片| 国产福利电影在线播放| 亚洲一区av| 成人久久一区| 69精品国产久热在线观看| 日韩视频网站在线观看| 日韩精品中文字幕一区二区| 色爱av综合网| 国产欧美在线观看免费| 午夜久久tv| 久久精品国产一区二区| 亚洲青青久久| 91精品精品| 乱一区二区av|