欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用IDEA搭建ssm框架的詳細(xì)圖文教程

 更新時間:2020年09月08日 09:51:48   作者:時光斑駁了記憶  
這篇文章主要介紹了使用IDEA搭建ssm框架的詳細(xì)教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

ssm(spring springMVC mybatis)

1.創(chuàng)建項目

file->new->project

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

2.新建的maven項目目錄結(jié)構(gòu)

在這里插入圖片描述

添加ssm需要的文件夾等

在這里插入圖片描述

如果去掉java文件夾的藍色標(biāo)志,會發(fā)現(xiàn)這里new時不能創(chuàng)建java類或包

在這里插入圖片描述

在這里插入圖片描述

如果main/java前不是藍色文件夾或test/java前不是綠色文件夾,可以這樣添加

在這里插入圖片描述

在這里插入圖片描述

3.加入maven依賴

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <groupId>org.example</groupId>
 <artifactId>ssm3</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>war</packaging>

 <name>ssm3 Maven Webapp</name>
 <!-- FIXME change it to the project's website -->
 <url>http://www.example.com</url>

 <properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <maven.compiler.source>1.7</maven.compiler.source>
 <maven.compiler.target>1.7</maven.compiler.target>
 <jackson.version>2.5.4</jackson.version>
 </properties>

 <dependencies>

 <!-- controller返回json -->
 <dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-core</artifactId>
  <version>${jackson.version}</version>
 </dependency>

 <dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>${jackson.version}</version>
 </dependency>

 <!-- 引入spring mvc的jar包 -->
 <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.3.7.RELEASE</version>
 </dependency>

 <!-- JDBC支持包,包括數(shù)據(jù)源設(shè)置和JDBC訪問支持 -->
 <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>4.3.7.RELEASE</version>
 </dependency>


 <!-- Spring提供對AspectJ框架的整合 -->
 <!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aspects</artifactId>
  <version>4.3.7.RELEASE</version>
 </dependency>


 <!-- mybatis依賴包 -->
 <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
 <dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis</artifactId>
  <version>3.4.2</version>
 </dependency>


 <!-- mybatis引入spring適配包 -->
 <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
 <dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis-spring</artifactId>
  <version>1.3.1</version>
 </dependency>


 <!-- 數(shù)據(jù)庫連接池 c3p0 -->
 <!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
 <dependency>
  <groupId>c3p0</groupId>
  <artifactId>c3p0</artifactId>
  <version>0.9.1.2</version>
 </dependency>


 <!-- mysql驅(qū)動 -->
 <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
 <dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.13</version>
 </dependency>

 <!-- jstl標(biāo)簽相關(guān)的包 -->
 <!-- https://mvnrepository.com/artifact/jstl/jstl -->
 <dependency>
  <groupId>jstl</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
 </dependency>


 <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
 <dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.0.1</version>
  <scope>provided</scope>
 </dependency>


 <!-- 逆向工程jar包 -->
 <!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
 <dependency>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-core</artifactId>
  <version>1.3.5</version>
 </dependency>


 <!--分頁依賴的jar包-->
 <dependency>
  <groupId>com.github.pagehelper</groupId>
  <artifactId>pagehelper</artifactId>
  <version>5.0.0</version>
 </dependency>

 </dependencies>

 <build>
 <finalName>ssm3</finalName>
 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
  <plugins>
  <plugin>
   <artifactId>maven-clean-plugin</artifactId>
   <version>3.1.0</version>
  </plugin>
  <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
  <plugin>
   <artifactId>maven-resources-plugin</artifactId>
   <version>3.0.2</version>
  </plugin>
  <plugin>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>3.8.0</version>
  </plugin>
  <plugin>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>2.22.1</version>
  </plugin>
  <plugin>
   <artifactId>maven-war-plugin</artifactId>
   <version>3.2.2</version>
  </plugin>
  <plugin>
   <artifactId>maven-install-plugin</artifactId>
   <version>2.5.2</version>
  </plugin>
  <plugin>
   <artifactId>maven-deploy-plugin</artifactId>
   <version>2.8.2</version>
  </plugin>
  </plugins>
 </pluginManagement>
 </build>
</project>

在這里插入圖片描述

4.加入spring配置文件(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">


 <!-- spring 配置文件 主要配置和業(yè)務(wù)邏輯有關(guān)的 -->

 <!-- 配置數(shù)據(jù)庫連接的相關(guān)信息 dbconfig.properties也定義在resources文件夾下-->
 <context:property-placeholder location="classpath:dbconfig.properties"/>
 <!-- 數(shù)據(jù)源 -->
 <bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
  <property name="driverClass" value="${jdbc.driverClass}"></property>
  <property name="user" value="${jdbc.user}"></property>
  <property name="password" value="${jdbc.password}"></property>
 </bean>


 <!--掃描com.ssm所有的除了@Controller以外的其它注解,也就是service和dao層的注解
  service層注解 @Service dao層注解@Repository
 -->
 <context:component-scan base-package="com.ssm">
  <!-- 不能掃描控制器 -->
 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>


 <!-- 把mybatis和spring整合在一起,mybatis-config.xml也和applictionContext.xml同文件夾
   mapper/星號.xml 指定要掃描的映射文件(sql語句的xml文件)的路徑,和applictionContext.xml同文件夾 -->
 <!-- 配置和mybatis的整合 -->
 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <!-- 指定mybatis 全局配置文件的位置 -->
  <property name="configLocation" value="classpath:mybatis-config.xml"></property>
  <property name="dataSource" ref="pooledDataSource"></property>
  <!-- 指定mybatismapper文件的位置 -->
  <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
 </bean>



 <!-- 配置掃描器,將mybatis接口的實現(xiàn)加入到ioc容器中 -->
 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  <!-- 掃描所有的dao接口 -->
  <property name="basePackage" value="com.ssm.dao"></property>
 </bean>

 <!-- 事務(wù)控制的配置,為所有的非get開頭的service層方法織入事務(wù) -->

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <!-- 控制數(shù)據(jù)源 -->
  <property name="dataSource" ref="pooledDataSource"></property>
 </bean>

 <aop:config>
  <!-- 切入點表達式 -->
  <aop:pointcut expression="execution(* com.liuzhan.service..*(..) )" id="txPoint"/>
  <!-- 配置事務(wù) -->
  <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
 </aop:config>
 <!-- 配置事務(wù)增強 事務(wù)如何切入 -->
 <tx:advice id="txAdvice">

  <tx:attributes>
   <!-- 所有方法都是事務(wù)方法 -->
   <tx:method name="*"/>
   <!-- 以get開頭的所有方法 -->
   <tx:method name="get*" read-only="true"/>
  </tx:attributes>
 </tx:advice>
</beans>

5.配置數(shù)據(jù)庫連接相關(guān)信息(dbconfig.properties)

在這里插入圖片描述

#數(shù)據(jù)庫連接
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm-crud?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
#加載驅(qū)動
jdbc.driverClass=com.mysql.cj.jdbc.Driver
#數(shù)據(jù)庫登錄用戶名
jdbc.user=root
#密碼
jdbc.password=root

6.mybatis配置文件(mybatis-config.xml)

在這里插入圖片描述

<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

</configuration>

注意:這里要建個mapper空文件,因為spring的配置文件applicationContext.xml
中有一項配置要掃描這個文件夾下的所有映射文件

在這里插入圖片描述

7.配置web.xml文件

web.xml
項目啟動,先加載web.xml文件的配置

在這里插入圖片描述

<!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
 <display-name>Archetype Created Web Application</display-name>

 <!-- 1.啟動spring容器,加載spring配置文件applicationContext.xml -->
 <!-- needed for ContextLoaderListener -->
 <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath:applicationContext.xml</param-value>
 </context-param>

 <!-- Bootstraps the root web application context before servlet initialization -->
 <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>


 <!-- 2. 配置spring mvc 的前端控制器,DispatcherServlet類攔截所有請求,交給controller處理
 加載spring mvc配置文件(dispatcherServlet-servlrt.xml,還沒有建) -->
 <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
 <servlet>
 <servlet-name>dispatcherServlet</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <!-- 不寫,寫的話需要建個springmvc.xml就不需要dispatcherServlet-servlrt.xml -->
 <!-- <init-param>-->
 <!--  <param-name>contextConfigLocation</param-name>-->
 <!--  <param-value>classpath:springmvc.xml</param-value>-->
 <!-- </init-param>-->
 <load-on-startup>1</load-on-startup>
 </servlet>

 <!-- Map all requests to the DispatcherServlet for handling -->
 <servlet-mapping>
 <servlet-name>dispatcherServlet</servlet-name>
 <url-pattern>/</url-pattern>
 </servlet-mapping>



 <!-- 編碼過濾器,防止出現(xiàn)亂碼 -->
 <filter>
 <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
</web-app>

8.配置spring mvc配置文件(dispatcherServlet-servlet.xml)

spring mvc就是充當(dāng)控制器,替代servlet

在這里插入圖片描述

<?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 http://www.springframework.org/schema/mvc/spring-mvc.xsd">



 <!-- spring mvc主要作用就是充當(dāng)控制器,只需要掃描controller -->
 <context:component-scan base-package="com.ssm" use-default-filters="false">
  <!-- 因為是spring mvc 只需要掃描控制器 -->
  <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
 </context:component-scan>

 <!-- 配置視圖解析器 -->
 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/views/"></property>
  <property name="suffix" value=".jsp"></property>
 </bean>

 <!-- 兩個標(biāo)準(zhǔn)配置 -->
 <!-- 將springmvc 不能處理的請求交給tomcat 例如靜態(tài)資源 -->
 <mvc:default-servlet-handler/>

 <mvc:annotation-driven>
  <mvc:message-converters>
   <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
   <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
  </mvc:message-converters>
 </mvc:annotation-driven>
</beans>

9.使用逆向工程前配置

在這里插入圖片描述

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>

 <context id="DB2Tables" targetRuntime="MyBatis3">
  <!-- 配置數(shù)據(jù)連接信息 -->
  <jdbcConnection driverClass="com.mysql.jdbc.Driver"
      connectionURL="jdbc:mysql://localhost:3306/ssm-crud?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=GMT%2B8"
      userId="root"
      password="root">
  </jdbcConnection>

  <javaTypeResolver >
   <property name="forceBigDecimals" value="false" />
  </javaTypeResolver>

  <!-- 指定java bean生成的位置 -->
  <javaModelGenerator targetPackage="com.ssm.entity" targetProject=".\src\main\java">
   <property name="enableSubPackages" value="true" />
   <property name="trimStrings" value="true" />
  </javaModelGenerator>

  <!-- 指定sql映射文件生成的位置 -->
  <sqlMapGenerator targetPackage="mapper"
       targetProject=".\src\main\resources">
   <property name="enableSubPackages" value="true" />
  </sqlMapGenerator>
  <!-- 指定dao接口生成的位置 -->
  <javaClientGenerator type="XMLMAPPER"
        targetPackage="com.ssm.dao"
        targetProject=".\src\main\java">
   <property name="enableSubPackages" value="true" />
  </javaClientGenerator>
  <!-- 指定每個表的生成策略,表和類對應(yīng)關(guān)系 -->
  <table tableName="tbl_emp" domainObjectName="Employee"></table>
  <table tableName="tbl_dept" domainObjectName="Department"></table>
 </context>
</generatorConfiguration>

10.使用逆向工程生成接口、實體類、映射文件

在這里插入圖片描述

MBGTest.java

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MBGTest {
 public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
  List<String> warnings = new ArrayList<String>();
  boolean overwrite = true;
  File configFile = new File("mbg.xml");
  ConfigurationParser cp = new ConfigurationParser(warnings);
  Configuration config = cp.parseConfiguration(configFile);
  DefaultShellCallback callback = new DefaultShellCallback(overwrite);
  MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
  myBatisGenerator.generate(null);
 }
}

逆向工程生成

在這里插入圖片描述

總結(jié)

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

相關(guān)文章

  • Jenkins配置自動發(fā)送郵件過程圖解

    Jenkins配置自動發(fā)送郵件過程圖解

    這篇文章主要介紹了jenkins配置自動發(fā)送郵件過程圖解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-02-02
  • springboot+redis過期事件監(jiān)聽實現(xiàn)過程解析

    springboot+redis過期事件監(jiān)聽實現(xiàn)過程解析

    這篇文章主要介紹了springboot+redis過期事件監(jiān)聽實現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-03-03
  • 將java程序打成jar包在cmd命令行下執(zhí)行的方法

    將java程序打成jar包在cmd命令行下執(zhí)行的方法

    這篇文章主要給大家介紹了關(guān)于將java程序打成jar包在cmd命令行下執(zhí)行的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01
  • 使用java反射將結(jié)果集封裝成為對象和對象集合操作

    使用java反射將結(jié)果集封裝成為對象和對象集合操作

    這篇文章主要介紹了使用java反射將結(jié)果集封裝成為對象和對象集合操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Spring?Boot?集成PageHelper的使用方法

    Spring?Boot?集成PageHelper的使用方法

    這篇文章主要介紹了Spring?Boot?集成PageHelper的使用方法,文章內(nèi)容圍繞主題展開詳細(xì)介紹,需要的小伙伴可以參考一下,希望對你的學(xué)習(xí)有所幫助
    2022-04-04
  • TreeSet詳解和使用示例_動力節(jié)點Java學(xué)院整理

    TreeSet詳解和使用示例_動力節(jié)點Java學(xué)院整理

    TreeSet是一個有序的集合,它的作用是提供有序的Set集合。這篇文章主要介紹了TreeSet使用示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Ajax實現(xiàn)省市區(qū)三級聯(lián)動

    Ajax實現(xiàn)省市區(qū)三級聯(lián)動

    這篇文章主要為大家詳細(xì)介紹了jQuery ajax實現(xiàn)省市縣三級聯(lián)動的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能幫助到你
    2021-07-07
  • Session過期后自動跳轉(zhuǎn)到登錄頁面的實例代碼

    Session過期后自動跳轉(zhuǎn)到登錄頁面的實例代碼

    這篇文章主要介紹了Session過期后自動跳轉(zhuǎn)到登錄頁面實例代碼,非常不錯具有參考借鑒價值,需要的朋友可以參考下
    2016-06-06
  • 設(shè)計模式在Spring框架中的應(yīng)用匯總

    設(shè)計模式在Spring框架中的應(yīng)用匯總

    這篇文章主要介紹了設(shè)計模式在Spring框架中的應(yīng)用匯總,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-11-11
  • IDEA SSM框架整合配置及步驟詳解

    IDEA SSM框架整合配置及步驟詳解

    這篇文章主要介紹了IDEA SSM框架整合配置以及步驟,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03

最新評論