亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

使用IDEA搭建SSM框架的詳細(xì)教程(spring + springMVC +MyBatis)

瀏覽:3日期:2023-09-04 09:40:49
1 框架組成

Spring

SpringMVC

MyBatis

2 所需工具

Mysql 8.0.15

數(shù)據(jù)庫管理系統(tǒng),創(chuàng)建數(shù)據(jù)庫

Tomcat 8.5.51

用于部署web項目

Maven 3.6.1

項目構(gòu)建、項目依賴管理

lombok 1.18.10(可用可不用工具)

用于類注解創(chuàng)建setter、getter、無參構(gòu)造、全參構(gòu)造、toString等函數(shù)

注:只導(dǎo)入依賴,不安裝插件是不起作用的

3 搭建步驟

3.1 新建一個空Maven項目,填寫項目相關(guān)信息,完成

使用IDEA搭建SSM框架的詳細(xì)教程(spring + springMVC +MyBatis)

3.2 添加web框架支持

使用IDEA搭建SSM框架的詳細(xì)教程(spring + springMVC +MyBatis)

選擇現(xiàn)有框架支持

使用IDEA搭建SSM框架的詳細(xì)教程(spring + springMVC +MyBatis)

3.3 pom.xml導(dǎo)入依賴,設(shè)置Maven資源過濾

<!--導(dǎo)入依賴--><dependencies> <!--Junit--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <!--數(shù)據(jù)庫驅(qū)動--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.15</version> </dependency> <!-- 數(shù)據(jù)庫連接池 --> <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> <!--lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> </dependency></dependencies><!--靜態(tài)資源導(dǎo)出問題--><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>

3.4 編寫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> <!--設(shè)置運(yùn)行日志--> <settings> <setting name='logImpl' value='STDOUT_LOGGING'/> </settings> <!--取別名--> <typeAliases> <package name='com.pojo'/> </typeAliases> <!--綁定mapper,根據(jù)自己的項目設(shè)置--> <mappers> <mapper resource='com/dao/Mapper.xml'/> </mappers></configuration>

3.5 編寫database.properties(數(shù)據(jù)庫配置文件)

jdbc.driver=com.mysql.cj.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/數(shù)據(jù)庫名?useSSL=true&useUnicode=true&characterEncoding=utf8jdbc.username=數(shù)據(jù)庫用戶名jdbc.password=數(shù)據(jù)庫密碼

​根據(jù)自己的MySQL以及項目實(shí)際使用的數(shù)據(jù)庫來修改設(shè)置

​注:MySQL8.0以上驅(qū)動得使用com.mysql.cj.jdbc.Driver

3.6 編寫Spring-dao.xml(Spring整合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 https://www.springframework.org/schema/context/spring-context.xsd'> <!-- 配置整合mybatis --> <!-- 1.關(guān)聯(lián)數(shù)據(jù)庫文件 --> <context:property-placeholder location='classpath:database.properties'/> <!-- 2.數(shù)據(jù)庫連接池 --> <!--數(shù)據(jù)庫連接池 dbcp 半自動化操作 不能自動連接 c3p0 自動化操作(自動的加載配置文件 并且設(shè)置到對象里面) --> <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'/> <!-- 關(guān)閉連接后不自動commit --> <property name='autoCommitOnClose' value='false'/> <!-- 獲取連接超時時間 --> <property name='checkoutTimeout' value='10000'/> <!-- 當(dāng)獲取連接失敗重試次數(shù) --> <property name='acquireRetryAttempts' value='2'/> </bean> <!-- 3.配置SqlSessionFactory對象 --> <bean class='org.mybatis.spring.SqlSessionFactoryBean'> <!-- 注入數(shù)據(jù)庫連接池 --> <property name='dataSource' ref='dataSource'/> <!-- 配置MyBaties全局配置文件:MyBatis-config.xml --> <property name='configLocation' value='classpath:MyBatis-config.xml'/> </bean> <!-- 4.配置掃描Dao接口包,動態(tài)實(shí)現(xiàn)Dao接口注入到spring容器中 --> <!--解釋 :https://www.cnblogs.com/jpfss/p/7799806.html--> <bean class='org.mybatis.spring.mapper.MapperScannerConfigurer'> <!-- 注入sqlSessionFactory --> <property name='sqlSessionFactoryBeanName' value='sqlSessionFactory'/> <!-- 給出需要掃描Dao接口包 --> <property name='basePackage' value='com.dao'/> </bean></beans>

3.7 編寫Spring-service.xml(Spring整合service層)

<?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'> <!-- 掃描service相關(guān)的bean --> <context:component-scan base-package='com.service' /> <!--ServiceImpl注入到IOC容器中,此處需要修改成自己的--> <bean class='com.service.ServiceImpl'> <property name='Mapper' ref='Mapper'/> </bean> <!-- 配置事務(wù)管理器 --> <bean class='org.springframework.jdbc.datasource.DataSourceTransactionManager'> <!-- 注入數(shù)據(jù)庫連接池 --> <property name='dataSource' ref='dataSource' /> </bean></beans>

3.8 修改web.xml文件

<?xml version='1.0' encoding='UTF-8'?><web-app xmlns='http://xmlns.jcp.org/xml/ns/javaee' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd' version='4.0'> <!--DispatcherServlet--> <servlet> <servlet-name>DispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <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>DispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--encodingFilter--> <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>

3.9 編寫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:context='http://www.springframework.org/schema/context' xmlns:mvc='http://www.springframework.org/schema/mvc' 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/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd'> <!-- 配置SpringMVC --> <!-- 1.開啟SpringMVC注解驅(qū)動 --> <mvc:annotation-driven /> <!-- 2.靜態(tài)資源默認(rèn)servlet配置--> <mvc:default-servlet-handler/> <!-- 3.配置jsp 顯示ViewResolver視圖解析器 --> <bean class='org.springframework.web.servlet.view.InternalResourceViewResolver'> <property name='viewClass' value='org.springframework.web.servlet.view.JstlView' /> <!--此處注意路徑問題,/WEB-INF/jsp/--> <property name='prefix' value='/WEB-INF/jsp/' /> <property name='suffix' value='.jsp' /> </bean> <!-- 4.掃描web相關(guān)的bean --> <context:component-scan base-package='com.controller' /></beans>

3.10 編寫applicationContext.xml(Spring配置整合文件)

<?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'> <!--將Spring其他配置文件整合到一個總的配置文件,用的時候使用這個配置文件--> <import resource='classpath:Spring-service.xml'/> <import resource='classpath:Spring-dao.xml'/> <import resource='classpath:Spring-mvc.xml'/></beans>

3.11 配置Tomcat

使用IDEA搭建SSM框架的詳細(xì)教程(spring + springMVC +MyBatis)

3.12 檢查項目結(jié)構(gòu)(左上角 文件 -> 項目結(jié)構(gòu))

使用IDEA搭建SSM框架的詳細(xì)教程(spring + springMVC +MyBatis)

3.13 最后的項目文件結(jié)構(gòu)

使用IDEA搭建SSM框架的詳細(xì)教程(spring + springMVC +MyBatis)

​到了這里,框架已經(jīng)搭建完成

4 接口對應(yīng)的Mapper.xml

<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE mapper PUBLIC '-//mybatis.org//DTD Mapper 3.0//EN' 'http://mybatis.org/dtd/mybatis-3-mapper.dtd'><!--綁定對應(yīng)的接口--><mapper namespace='com.dao.Mapper'> <!--此處寫對應(yīng)的SQL操作--></mapper>5 功能添加步驟 先編寫實(shí)體類(pojo) dao層:編寫接口,接口對應(yīng)mapper.xml(建議同名) service層:編寫接口,編寫接口實(shí)現(xiàn)類(創(chuàng)建dao層對象,返回調(diào)用dao層的操作) controller層:負(fù)責(zé)具體的業(yè)務(wù)模塊流程的控制,在此層要調(diào)用service層的接口來控制業(yè)務(wù)流程 編寫相應(yīng)的jsp文件6 建議

框架搭建完成后應(yīng)寫個簡單的功能測試框架環(huán)境有無問題

7 SSM框架項目文件

http://xiazai.jb51.net/202005/yuanma/ssm_kuangjia_jb51.rar

總結(jié)

到此這篇關(guān)于使用IDEA搭建SSM框架的詳細(xì)教程 spring + springMVC +MyBatis的文章就介紹到這了,更多相關(guān)IDEA搭建SSM框架內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 亚洲欧美日韩国产精品第不页 | 欧美日韩国产片 | 亚洲三级黄| 韩国美女丝袜一区二区 | 97碰碰碰免费公开在线视频 | 国产在线观看91精品2022 | 一级做a爰片久久毛片图片 一级做a爰片久久毛片看看 | 成人性色生活片 | 国产成人精品午夜视频' | 一级毛片国产 | 国产午夜精品久久久久免费视 | 亚洲欧美一区二区三区二厂 | 成人免费激情视频 | 中国一级特黄真人毛片免费看 | 一级黄色a | 日本黄色免费一级片 | 嫩草影院麻豆久久视频 | 欧美在线观看日韩欧美在线观看 | 国产成人做受免费视频 | 亚洲精品123区在线观看 | 在线观看麻豆视频 | 黄色网址在线播放 | 久久丝袜视频 | 日韩国产欧美在线观看一区二区 | 国产aaa级一级毛片 国产aaa免费视频国产 | 黄污在线观看 | 日本久久综合网 | 国产精品13页 | 免费中文字幕视频 | 黄色的视频免费观看 | 国产视频黄 | 精品亚洲一区二区三区 | 日韩丝袜在线观看 | 免费国产一级特黄久久 | 婷婷色天使在线视频观看 | 免费黄网在线观看 | 久久国产精品视频一区 | 成人福利短视频 | 97国内精品久久久久久久影视 | 精品国产品香蕉在线观看75 | 国产日韩欧美不卡www |