栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

使用IDEA搭建ssm框架的详细图文教程

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用IDEA搭建ssm框架的详细图文教程

ssm(spring springMVC mybatis)

1.创建项目

file->new->project



2.新建的maven项目目录结构

添加ssm需要的文件夹等

如果去掉java文件夹的蓝色标志,会发现这里new时不能创建java类或包

如果main/java前不是蓝色文件夹或test/java前不是绿色文件夹,可以这样添加

3.加入maven依赖

pom.xml




 4.0.0

 org.example
 ssm3
 1.0-SNAPSHOT
 war

 ssm3 Maven Webapp
 
 http://www.example.com

 
 UTF-8
 1.7
 1.7
 2.5.4
 

 

 
 
  com.fasterxml.jackson.core
  jackson-core
  ${jackson.version}
 

 
  com.fasterxml.jackson.core
  jackson-databind
  ${jackson.version}
 

 
 
 
  org.springframework
  spring-webmvc
  4.3.7.RELEASE
 

 
 
 
  org.springframework
  spring-jdbc
  4.3.7.RELEASE
 


 
 
 
  org.springframework
  spring-aspects
  4.3.7.RELEASE
 


 
 
 
  org.mybatis
  mybatis
  3.4.2
 


 
 
 
  org.mybatis
  mybatis-spring
  1.3.1
 


 
 
 
  c3p0
  c3p0
  0.9.1.2
 


 
 
 
  mysql
  mysql-connector-java
  8.0.13
 

 
 
 
  jstl
  jstl
  1.2
 


 
 
  javax.servlet
  javax.servlet-api
  3.0.1
  provided
 


 
 
 
  org.mybatis.generator
  mybatis-generator-core
  1.3.5
 


 
 
  com.github.pagehelper
  pagehelper
  5.0.0
 

 

 
 ssm3
 
  
  
   maven-clean-plugin
   3.1.0
  
  
  
   maven-resources-plugin
   3.0.2
  
  
   maven-compiler-plugin
   3.8.0
  
  
   maven-surefire-plugin
   2.22.1
  
  
   maven-war-plugin
   3.2.2
  
  
   maven-install-plugin
   2.5.2
  
  
   maven-deploy-plugin
   2.8.2
  
  
 
 

4.加入spring配置文件(applicationContext.xml)





 

 
 
 
 
  
  
  
  
 


 
 
  
  


 
 
 
  
  
  
  
  
 



 
 
  
  
 

 

 
  
  
 

 
  
  
  
  
 
 
 

  
   
   
   
   
  
 

5.配置数据库连接相关信息(dbconfig.properties)

#数据库连接
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm-crud?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
#加载驱动
jdbc.driverClass=com.mysql.cj.jdbc.Driver
#数据库登录用户名
jdbc.user=root
#密码
jdbc.password=root

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





注意:这里要建个mapper空文件,因为spring的配置文件applicationContext.xml
中有一项配置要扫描这个文件夹下的所有映射文件

7.配置web.xml文件

web.xml
项目启动,先加载web.xml文件的配置




 Archetype Created Web Application

 
 
 
 contextConfigLocation
 classpath:applicationContext.xml
 

 
 
 org.springframework.web.context.ContextLoaderListener
 


 
 
 
 dispatcherServlet
 org.springframework.web.servlet.DispatcherServlet
 
 
 
 
 
 1
 

 
 
 dispatcherServlet
 /
 



 
 
 characterEncodingFilter
 org.springframework.web.filter.CharacterEncodingFilter
 
  encoding
  UTF-8
 
 

 
 characterEncodingFilter
 /*
 

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

spring mvc就是充当控制器,替代servlet






 
 
  
  
 

 
 
  
  
 

 
 
 

 
  
   
   
  
 

9.使用逆向工程前配置






 
  
  
  

  
   
  

  
  
   
   
  

  
  
   
  
  
  
   
  
  
  

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 warnings = new ArrayList();
  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);
 }
}

逆向工程生成

总结

到此这篇关于使用IDEA搭建ssm框架的详细图文教程的文章就介绍到这了,更多相关IDEA搭建ssm框架内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/131978.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号