当前位置: 首页 > 编程笔记 >

使用IntelliJ IDEA搭建SSM框架的图文教程

胡志
2023-03-14
本文向大家介绍使用IntelliJ IDEA搭建SSM框架的图文教程,包括了使用IntelliJ IDEA搭建SSM框架的图文教程的使用技巧和注意事项,需要的朋友参考一下

1.使用IDEA新建项目

2.选择创建Maven工程

3.填写GroupId和ArtifactId


4.填写项目名称,与上一步的ArtifactId一致即可,然后点Finish


5.刚建好的目录只是一个Maven的目录结构,如下

6.完善目录结构,添加webapp、WEB-INF目录,以及web.xml文件


7.修改IDEA的Maven设置,Maven默认的本地仓库会保存在C盘,为了方便以后使用,尽量修改本地仓库的位置,因为这是框架整合,所以具体的修改方式在这里不多做说明。快捷键ctrl+alt+s,在搜索框中搜索Maven,如下



9.修改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>com.xiao</groupId> 
 <artifactId>SSM</artifactId> 
 <version>1.0-SNAPSHOT</version> 
 <packaging>war</packaging> 
 <!-- 提取版本属性 --> 
 <properties> 
  <spring.version>4.2.4.RELEASE</spring.version> 
  <mybatis.version>3.2.8</mybatis.version> 
  <mybatis.spring.version>1.2.2</mybatis.spring.version> 
  <slf4j.version>1.6.4</slf4j.version> 
  <log4j.version>1.2.17</log4j.version> 
  <jackson.version>2.4.2</jackson.version> 
  <druid.version>1.0.9</druid.version> 
  <mysql.version>5.1.32</mysql.version> 
  <jstl.version>1.2</jstl.version> 
  <servlet-api.version>2.5</servlet-api.version> 
  <jsp-api.version>2.0</jsp-api.version> 
  <commons-io.version>1.3.2</commons-io.version> 
  <commons-fileupload.version>1.3.1</commons-fileupload.version> 
 </properties> 
 <!-- 版本锁定 --> 
 <dependencyManagement> 
  <dependencies> 
   <!-- Spring --> 
   <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-context</artifactId> 
    <version>${spring.version}</version> 
   </dependency> 
   <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-beans</artifactId> 
    <version>${spring.version}</version> 
   </dependency> 
   <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-webmvc</artifactId> 
    <version>${spring.version}</version> 
   </dependency> 
   <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-jdbc</artifactId> 
    <version>${spring.version}</version> 
   </dependency> 
   <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-aspects</artifactId> 
    <version>${spring.version}</version> 
   </dependency> 
   <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-jms</artifactId> 
    <version>${spring.version}</version> 
   </dependency> 
   <dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-context-support</artifactId> 
    <version>${spring.version}</version> 
   </dependency> 
   <!-- Mybatis --> 
   <dependency> 
    <groupId>org.mybatis</groupId> 
    <artifactId>mybatis</artifactId> 
    <version>${mybatis.version}</version> 
   </dependency> 
   <dependency> 
    <groupId>org.mybatis</groupId> 
    <artifactId>mybatis-spring</artifactId> 
    <version>${mybatis.spring.version}</version> 
   </dependency> 
   <!-- 日志处理 --> 
   <dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId> 
    <version>${slf4j.version}</version> 
   </dependency> 
   <dependency> 
    <groupId>log4j</groupId> 
    <artifactId>log4j</artifactId> 
    <version>${log4j.version}</version> 
   </dependency> 
   <!-- Jackson Json处理工具包 --> 
   <dependency> 
    <groupId>com.fasterxml.jackson.core</groupId> 
    <artifactId>jackson-databind</artifactId> 
    <version>${jackson.version}</version> 
   </dependency> 
   <!-- 连接池 --> 
   <dependency> 
    <groupId>com.alibaba</groupId> 
    <artifactId>druid</artifactId> 
    <version>${druid.version}</version> 
   </dependency> 
   <!-- MySql --> 
   <dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>${mysql.version}</version> 
   </dependency> 
   <!-- io包 --> 
   <dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-io</artifactId> 
    <version>${commons-io.version}</version> 
   </dependency> 
   <!-- 文件上传组件 --> 
   <dependency> 
    <groupId>commons-fileupload</groupId> 
    <artifactId>commons-fileupload</artifactId> 
    <version>${commons-fileupload.version}</version> 
   </dependency> 
   <!-- JSP相关 --> 
   <dependency> 
    <groupId>jstl</groupId> 
    <artifactId>jstl</artifactId> 
    <version>${jstl.version}</version> 
   </dependency> 
   <dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>servlet-api</artifactId> 
    <version>${servlet-api.version}</version> 
    <scope>provided</scope> 
   </dependency> 
   <dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>jsp-api</artifactId> 
    <version>${jsp-api.version}</version> 
    <scope>provided</scope> 
   </dependency> 
  </dependencies> 
 </dependencyManagement> 
 <!-- 添加依赖 --> 
 <dependencies> 
  <!-- Spring --> 
  <dependency> 
   <groupId>org.springframework</groupId> 
   <artifactId>spring-context</artifactId> 
  </dependency> 
  <dependency> 
   <groupId>org.springframework</groupId> 
   <artifactId>spring-beans</artifactId> 
  </dependency> 
  <dependency> 
   <groupId>org.springframework</groupId> 
   <artifactId>spring-webmvc</artifactId> 
  </dependency> 
  <dependency> 
   <groupId>org.springframework</groupId> 
   <artifactId>spring-jdbc</artifactId> 
  </dependency> 
  <dependency> 
   <groupId>org.springframework</groupId> 
   <artifactId>spring-aspects</artifactId> 
  </dependency> 
  <dependency> 
   <groupId>org.springframework</groupId> 
   <artifactId>spring-jms</artifactId> 
  </dependency> 
  <dependency> 
   <groupId>org.springframework</groupId> 
   <artifactId>spring-context-support</artifactId> 
  </dependency> 
  <!-- Mybatis --> 
  <dependency> 
   <groupId>org.mybatis</groupId> 
   <artifactId>mybatis</artifactId> 
  </dependency> 
  <dependency> 
   <groupId>org.mybatis</groupId> 
   <artifactId>mybatis-spring</artifactId> 
  </dependency> 
  <!-- 日志处理 --> 
  <dependency> 
   <groupId>org.slf4j</groupId> 
   <artifactId>slf4j-log4j12</artifactId> 
  </dependency> 
  <!-- Jackson Json处理工具包 --> 
  <dependency> 
   <groupId>com.fasterxml.jackson.core</groupId> 
   <artifactId>jackson-databind</artifactId> 
  </dependency> 
  <!-- 连接池 --> 
  <dependency> 
   <groupId>com.alibaba</groupId> 
   <artifactId>druid</artifactId> 
  </dependency> 
  <!-- MySql --> 
  <dependency> 
   <groupId>mysql</groupId> 
   <artifactId>mysql-connector-java</artifactId> 
  </dependency> 
  <!-- io包 --> 
  <dependency> 
   <groupId>org.apache.commons</groupId> 
   <artifactId>commons-io</artifactId> 
  </dependency> 
  <!-- 文件上传组件 --> 
  <dependency> 
   <groupId>commons-fileupload</groupId> 
   <artifactId>commons-fileupload</artifactId> 
  </dependency> 
  <!-- JSP相关 --> 
  <dependency> 
   <groupId>jstl</groupId> 
   <artifactId>jstl</artifactId> 
  </dependency> 
  <dependency> 
   <groupId>javax.servlet</groupId> 
   <artifactId>servlet-api</artifactId> 
   <scope>provided</scope> 
  </dependency> 
  <dependency> 
   <groupId>javax.servlet</groupId> 
   <artifactId>jsp-api</artifactId> 
   <scope>provided</scope> 
  </dependency> 
 </dependencies> 
 <build> 
  <!-- java编译插件 --> 
  <plugins> 
   <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.2</version> 
    <configuration> 
     <source>1.8</source> 
     <target>1.8</target> 
     <encoding>UTF-8</encoding> 
    </configuration> 
   </plugin> 
  </plugins> 
  <!--配置资源文件映射 --> 
  <resources> 
   <resource> 
    <directory>src/main/java</directory> 
    <includes> 
     <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> 
</project> 

10.在resources目录下添加配置文件

文件目录如下


a)连接数据库配置信息文件-db.properties

druid.driver=com.mysql.jdbc.Driver 
druid.url=jdbc:mysql://localhost:3306/all_db?characterEncoding=utf-8 
druid.username=root 
druid.password=root 

 b)Mybatis核心配置文件-SqlMapConfig.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> 
 <!-- 给实体类起别名 --> 
 <typeAliases > 
  <package name="com.xiao.pojo"/> 
 </typeAliases> 
 </configuration> 

c)Spring核心配置文件,整合Mybatis,applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://www.springframework.org/schema/beans" 
  xmlns:context="http://www.springframework.org/schema/context" 
  xmlns:tx="http://www.springframework.org/schema/tx" 
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd 
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd"> 
 <!-- 加载数据库连接信息配置文件 --> 
 <context:property-placeholder location="classpath:db.properties" /> 
 <!--druid连接池 --> 
 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> 
  <property name="driverClassName" value="${druid.driver}" /> 
  <property name="url"   value="${druid.url}" /> 
  <property name="username"   value="${druid.username}" /> 
  <property name="password"   value="${druid.password}" /> 
 </bean> 
 <!-- 配置Mybatis工厂 --> 
 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
  <property name="dataSource" ref="dataSource" /> 
  <property name="configLocation" value="classpath:SqlMapConfig.xml" /> 
 </bean> 
 <!-- Mapper动态代理开发 扫包 给定包下的接口文件名和映射文件名必须相同 创建接口的实现类--> 
 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 
  <property name="basePackage" value="com.xiao.mapper" /> 
 </bean> 
 <!-- 开启事物 --> 
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
  <property name="dataSource" ref="dataSource" /> 
 </bean> 
 <!-- 事物注解驱动--> 
 <tx:annotation-driven /> 
</beans> 

 d)SpringMVC配置文件-springmvc.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://www.springframework.org/schema/beans" 
  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-4.2.xsd 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd 
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"> 
 <!-- 配置扫描注解 @Controller @Service --> 
 <context:component-scan base-package="com.xiao" /> 
 <!-- SpringMVC使用<mvc:annotation-driven>自动加载RequestMappingHandlerMapping和RequestMappingHandlerAdapter --> 
 <mvc:annotation-driven /> 
 <!-- 配置静态资源映射 --> 
 <!-- 
 <mvc:resources location="/js/" mapping="/js/**"/> 
 <mvc:resources location="/css/" mapping="/css/**"/> 
 <mvc:resources location="/imgs/" mapping="/imgs/**"/> 
 <mvc:resources location="/font/" mapping="/font/**"/> 
 --> 
 <!-- 配置视图解析器--> 
 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
  <!-- 配置逻辑视图的前缀 --> 
  <property name="prefix" value="/WEB-INF/jsp/" /> 
  <!-- 配置逻辑视图的后缀 --> 
  <property name="suffix" value=".jsp" /> 
 </bean> 
</beans> 

11.配置web.xml文件

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
   version="2.5"> 
 <display-name>SSM</display-name> 
 <welcome-file-list> 
  <welcome-file>index.jsp</welcome-file> 
 </welcome-file-list> 
 <!-- spring监听器 --> 
 <listener> 
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
 </listener> 
 <!-- 指定spring核心配置文件 --> 
 <context-param> 
  <param-name>contextConfigLocation</param-name> 
  <param-value>classpath:applicationContext.xml</param-value> 
 </context-param> 
 <!-- 处理POST提交乱码问题 --> 
 <filter> 
  <filter-name>encoding</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>encoding</filter-name> 
  <url-pattern>/*</url-pattern> 
 </filter-mapping> 
 <!-- 配置前端控制器 --> 
 <servlet> 
  <servlet-name>springmvc</servlet-name> 
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
  <!-- 指定配置文件位置和名称 如果不设置,默认找/WEB-INF/<servlet-name>-servlet.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> 
 <servlet-mapping> 
  <servlet-name>springmvc</servlet-name> 
  <url-pattern>/</url-pattern> 
 </servlet-mapping> 
</web-app> 

12.完善目录结构,书写实体类、web层、service层、dao层以及测试页面,目录结构如下


13.配置tomcat







14.启动Tomcat,访问地址: http://localhost:8080/getAll   进行测试,结果如下

出现以上结果,表示SSM框架搭建成功!

数据库数据如下

在jsp页面用EL表达式取值

总结

以上所述是小编给大家介绍的使用IntelliJ IDEA搭建SSM框架的图文教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对小牛知识库网站的支持!

 类似资料:
  • 本文向大家介绍使用idea2017搭建SSM框架(图文步骤),包括了使用idea2017搭建SSM框架(图文步骤)的使用技巧和注意事项,需要的朋友参考一下 搭建个SSM框架居然花费了我好长时间!特此记录! 需要准备的环境: idea 2017.1 jdk1.8 Maven 3.3.9 请提前将idea与Maven、jdk配置好,本次项目用的都是比较新的 注:配置完ide红线报错没关系!可以run!

  • 本文向大家介绍使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis),包括了使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)的使用技巧和注意事项,需要的朋友参考一下 1 框架组成 Spring SpringMVC MyBatis 2 所需工具 Mysql 8.0.15 ​数据库管理系统,创建数据库 Tomcat

  • 本文向大家介绍SpringBoot框架搭建教程分享,包括了SpringBoot框架搭建教程分享的使用技巧和注意事项,需要的朋友参考一下 SpringBoot几乎集成了SpringMVC的所有内容,以及tomcat容器,同时去除了繁复的xml配置文件,开发起来十分方便;页面配合thymeleaf模板渲染也是非常简单,如果是前后端分离的项目,那么SpringBoot就专门负责提供restful风格的a

  • 本文向大家介绍详解idea搭建springboot+mybatis框架的教程,包括了详解idea搭建springboot+mybatis框架的教程的使用技巧和注意事项,需要的朋友参考一下 1.打开idea编译器,新建一个项目  2.选择Spring Initializr 勾选Default,完成之后点击【Next】 3.创建项目的文件目录结构以及选择jdk版本信息,设置完成后点击【Next】 4.

  • 本文向大家介绍spring框架下websocket的搭建,包括了spring框架下websocket的搭建的使用技巧和注意事项,需要的朋友参考一下 本文基于Apach Tomcat 8.0.3+MyEclipse+maven+JDK1.7 spring4.0以后加入了对websocket技术的支持,撸主目前的项目用的是SSM(springMVC+spring+MyBatis)框架,所以肯定要首选s

  • react.js简介 react.js 是作为前端渲染的js库(注意:不是框架)。react.js用JSX开发来描述DOM结构,通过编译成virtual dom的在浏览器中进行view渲染和动态交互处理。更多了解可查阅GitHubhttps://facebook.github.io/react/ 编译使用 由于react.js开发过程用JSX编程,无法直接在浏览器中运行,需要编译成浏览器可识别运行