1 框架组成
Spring
SpringMVC
MyBatis
2 所需工具
Mysql 8.0.15
数据库管理系统,创建数据库
Tomcat 8.5.51
用于部署web项目
Maven 3.6.1
项目构建、项目依赖管理
lombok 1.18.10(可用可不用工具)
用于类注解创建setter、getter、无参构造、全参构造、toString等函数
注:只导入依赖,不安装插件是不起作用的
3 搭建步骤
3.1 新建一个空Maven项目,填写项目相关信息,完成
3.2 添加web框架支持
选择现有框架支持
3.3 pom.xml导入依赖,设置Maven资源过滤
junit
junit
4.12
mysql
mysql-connector-java
8.0.15
com.mchange
c3p0
0.9.5.2
javax.servlet
servlet-api
2.5
javax.servlet.jsp
jsp-api
2.2
javax.servlet
jstl
1.2
org.mybatis
mybatis
3.5.2
org.mybatis
mybatis-spring
2.0.2
org.springframework
spring-webmvc
5.1.9.RELEASE
org.springframework
spring-jdbc
5.1.9.RELEASE
org.projectlombok
lombok
1.18.10
src/main/java
**/*.properties
**/*.xml
false
src/main/resources
**/*.properties
**/*.xml
false
3.4 编写MyBatis-config.xml(核心配置文件)
/p>
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
3.5 编写database.properties(数据库配置文件)
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/数据库名?useSSL=true&useUnicode=true&characterEncoding=utf8
jdbc.username=数据库用户名
jdbc.password=数据库密码
根据自己的MySQL以及项目实际使用的数据库来修改设置
注:MySQL8.0以上驱动得使用com.mysql.cj.jdbc.Driver
3.6 编写Spring-dao.xml(Spring整合MyBatis配置文件)
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">
3.7 编写Spring-service.xml(Spring整合service层)
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">
3.8 修改web.xml文件
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
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:applicationContext.xml
1
DispatcherServlet
/
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
encodingFilter
/*
15
3.9 编写Spring-mvc.xml
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">
3.10 编写applicationContext.xml(Spring配置整合文件)
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">
3.11 配置Tomcat
3.12 检查项目结构(左上角 文件 -> 项目结构)
3.13 最后的项目文件结构
到了这里,框架已经搭建完成
4 接口对应的Mapper.xml
/p>
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5 功能添加步骤
先编写实体类(pojo)
dao层:编写接口,接口对应mapper.xml(建议同名)
service层:编写接口,编写接口实现类(创建dao层对象,返回调用dao层的操作)
controller层:负责具体的业务模块流程的控制,在此层要调用service层的接口来控制业务流程
编写相应的jsp文件
6 建议
框架搭建完成后应写个简单的功能测试框架环境有无问题
7 SSM框架项目文件
总结
到此这篇关于使用IDEA搭建SSM框架的详细教程 spring + springMVC +MyBatis的文章就介绍到这了,更多相关IDEA搭建SSM框架内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!