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

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

 更新時間:2020年05月29日 11:46:03   作者:想不到啥名字  
這篇文章主要介紹了使用IDEA搭建SSM框架的詳細教程 spring + springMVC +MyBatis,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

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

項目構建、項目依賴管理

lombok 1.18.10(可用可不用工具)

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

注:只導入依賴,不安裝插件是不起作用的

3 搭建步驟

3.1 新建一個空Maven項目,填寫項目相關信息,完成

在這里插入圖片描述

3.2 添加web框架支持

在這里插入圖片描述

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

在這里插入圖片描述

3.3 pom.xml導入依賴,設置Maven資源過濾

<!--導入依賴-->
<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)資源導出問題-->
<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>
 
 <!--設置運行日志-->
 <settings>
 <setting name="logImpl" value="STDOUT_LOGGING"/>
 </settings>
 
 <!--取別名-->
 <typeAliases>
 <package name="com.pojo"/>
 </typeAliases>
 
 <!--綁定mapper,根據(jù)自己的項目設置-->
 <mappers>
 <mapper resource="com/dao/Mapper.xml"/>
 </mappers>

</configuration>

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

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

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

​注: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.關聯(lián)數(shù)據(jù)庫文件 -->
 <context:property-placeholder location="classpath:database.properties"/>

 <!-- 2.數(shù)據(jù)庫連接池 -->
 <!--數(shù)據(jù)庫連接池
 dbcp 半自動化操作 不能自動連接
 c3p0 自動化操作(自動的加載配置文件 并且設置到對象里面)
 -->
 <bean id="dataSource" 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"/>
 <!-- 當獲取連接失敗重試次數(shù) -->
 <property name="acquireRetryAttempts" value="2"/>
 </bean>

 <!-- 3.配置SqlSessionFactory對象 -->
 <bean id="sqlSessionFactory" 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)實現(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相關的bean -->
 <context:component-scan base-package="com.service" />

 <!--ServiceImpl注入到IOC容器中,此處需要修改成自己的-->
 <bean id="ServiceImpl" class="com.service.ServiceImpl">
 <property name="Mapper" ref="Mapper"/>
 </bean>

 <!-- 配置事務管理器 -->
 <bean id="transactionManager" 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)資源默認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相關的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

在這里插入圖片描述

3.12 檢查項目結構(左上角 文件 -> 項目結構)

在這里插入圖片描述

3.13 最后的項目文件結構

在這里插入圖片描述

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

4 接口對應的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">

<!--綁定對應的接口-->
<mapper namespace="com.dao.Mapper">
 <!--此處寫對應的SQL操作-->
</mapper>

5 功能添加步驟

  • 先編寫實體類(pojo)
  • dao層:編寫接口,接口對應mapper.xml(建議同名)
  • service層:編寫接口,編寫接口實現(xiàn)類(創(chuàng)建dao層對象,返回調(diào)用dao層的操作)
  • controller層:負責具體的業(yè)務模塊流程的控制,在此層要調(diào)用service層的接口來控制業(yè)務流程
  • 編寫相應的jsp文件

6 建議

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

7 SSM框架項目文件

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

總結

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

相關文章

  • SpringBoot配置攔截器實現(xiàn)過程詳解

    SpringBoot配置攔截器實現(xiàn)過程詳解

    在系統(tǒng)中經(jīng)常需要在處理用戶請求之前和之后執(zhí)行一些行為,例如檢測用戶的權限,或者將請求的信息記錄到日志中,即平時所說的"權限檢測"及"日志記錄",下面這篇文章主要給大家介紹了關于在SpringBoot項目中整合攔截器的相關資料,需要的朋友可以參考下
    2022-10-10
  • Spring MVC 4.1.3 + MyBatis零基礎搭建Web開發(fā)框架(注解模式)

    Spring MVC 4.1.3 + MyBatis零基礎搭建Web開發(fā)框架(注解模式)

    本篇文章主要介紹了Spring MVC 4.1.3 + MyBatis零基礎搭建Web開發(fā)框架(注解模式),具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • Java使用SFTP上傳文件到服務器的簡單使用

    Java使用SFTP上傳文件到服務器的簡單使用

    這篇文章主要介紹了Java使用SFTP上傳文件到服務器的簡單使用,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-02-02
  • struts2自定義MVC框架

    struts2自定義MVC框架

    這篇文章主要為大家詳細介紹了struts2如何自定義MVC框架,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Java動態(tài)獲取實現(xiàn)類的方式詳解

    Java動態(tài)獲取實現(xiàn)類的方式詳解

    這篇文章主要介紹了Java動態(tài)獲取實現(xiàn)類的方式詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或工作有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧
    2024-01-01
  • Idea集成ApiFox插件及使用小結

    Idea集成ApiFox插件及使用小結

    本文介紹了如何使用Apifox和IntelliJ IDEA插件來整理和生成接口文檔,包括配置Apifox和IntelliJ IDEA插件、代碼案例以及使用方法,感興趣的朋友跟隨小編一起看看吧
    2024-11-11
  • SpringBoot業(yè)務邏輯異常的處理方法介紹

    SpringBoot業(yè)務邏輯異常的處理方法介紹

    本篇文章為大家展示了如何在SpringBoot中統(tǒng)一處理邏輯異常,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲
    2022-09-09
  • java web實現(xiàn)網(wǎng)上手機銷售系統(tǒng)

    java web實現(xiàn)網(wǎng)上手機銷售系統(tǒng)

    這篇文章主要為大家詳細介紹了java web實現(xiàn)網(wǎng)上手機銷售系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • 深入理解Spring MVC概要與環(huán)境配置

    深入理解Spring MVC概要與環(huán)境配置

    本篇文章主要介紹了深入理解Spring MVC概要與環(huán)境配置 ,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • elasticsearch通過guice注入Node組裝啟動過程

    elasticsearch通過guice注入Node組裝啟動過程

    這篇文章主要為大家介紹了?elasticsearch通過guice注入Node組裝啟動過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-04-04

最新評論

阳朔县| 乡宁县| 临沧市| 东阳市| 临安市| 东辽县| 卓资县| 宁蒗| 疏勒县| 金华市| 绿春县| 南溪县| 修水县| 普格县| 资溪县| 开原市| 英德市| 思茅市| 新疆| 吴忠市| 汶上县| 镇平县| 延寿县| 东乡族自治县| 富平县| 社旗县| 化隆| 和平县| 太仓市| 泸水县| 泸州市| 黔东| 于都县| 岳普湖县| 潼关县| 通辽市| 柞水县| 台山市| 萨迦县| 华安县| 鄂州市|