本次SSM框架搭建使用IDEA+maven搭建,maven是一个自动化构建平台,可以根据配置文件自动下载jar包,具体配置过程可以百度。SSM框架分为3层架构:--持久层(dao)--业务层(biz)--表现层(web)整体框架结构可以参考下图:
idea中创建流程:
选择webapp模板
2.
填写组ID和个人ID
3.
选择自己安装好的maven路径,之后一直next,finish即可
4.
添加模块
不需要选择模板。之后与新建项目时一样,分别添加持久层,业务层和表现层即可
配置文件(pom.xml)共有4个,第一个是整体项目的配置文件主要是引入每个模块。
<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.lvlin</groupId>
<artifactId>vms</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>vms_dao</module>// 引入持久层(dao)模块
<module>vms_biz</module>//引入业务层(biz)模块
<module>vms_web</module>//引入表现层(web)模块
</modules>
<properties>
<spring_version>4.3.1.RELEASE</spring_version>//定义spring版本其他地方需要指定spring版本时可以使用spring_version
</properties>
</project>
1.持久层
持久层需要添加Mybatis依赖,spring依赖以及mybatis-Spring整合的依赖。负责与数据库进行交互设计,用来处理数据的持久化工作。
持久层配置文件:
<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">
<parent>
<artifactId>vms</artifactId>
<groupId>com.lvlin</groupId>
<version>1.0-SNAPSHOT</version>
</parent>//父模块
<modelVersion>4.0.0</modelVersion>
<artifactId>vms_dao</artifactId>
<dependencies>
<dependency>
<groupId>com.lvlin</groupId>
<artifactId>vms</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>//mysql连接
<version>5.1.44</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>spring整合mybatis
<version>2.0.2</version>
</dependency>
</dependencies>
</project>
2.业务层
配置Aspect依赖和AOP。主要负责业务模块的逻辑应用设计
业务层配置文件
<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">
<parent>
<artifactId>vms</artifactId>
<groupId>com.lvlin</groupId>
<version>1.0-SNAPSHOT</version>//父模块
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>vms_biz</artifactId>
<dependencies>
<dependency>
<groupId>com.lvlin</groupId>
<artifactId>vms</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lvlin</groupId>
<artifactId>vms_dao</artifactId>//引入持久层模块
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>//AOP
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>//Aspect
<version>1.8.6</version>
</dependency>
</dependencies>
</project>
3.表现层
配置Servlet依赖,SpringMVC依赖负责具体的业务模块流程控制。调用业务层接口控制业务流程。
表现层配置文件
<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">
<parent>
<artifactId>vms</artifactId>
<groupId>com.lvlin</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>vms_web</artifactId>
<packaging>war</packaging>
<name>vms_web 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>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>//单元测试
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lvlin</groupId>
<artifactId>vms_biz</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>//servlet
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>//SpringMVC依赖
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>//json依赖
<version>1.2.21</version>
</dependency>
</dependencies>
<build>
<finalName>vms_web</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>