Idea搭建Spring+SpringMvc+Mybatis框架集成项目
1.新建maven项目
2.创建多模块
每个模块配置如父模块一样,除视图层
(视图层配置)
最后
common-通过模块,不依赖任何模块,有各种项目所需要用到的工具类
model- POJO、VO、DTO
dao模块:数据持久化,访问数据库,这里使用Mybatis
service模块:业务模块,处理业务逻辑
webui模块:B/S结构的表示层,主要用于在浏览器中显示数据,提供用户接口
3.添加父模快插件版本管理
3.1代码如下:
<?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.tff.SSM05</groupId> <artifactId>SSM05</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> <module>Ssm05-common</module> <module>Ssm05-model</module> <module>Ssm05-dao</module> <module>Ssm05-service</module> <module>Ssm05-webui</module> </modules> <properties> <!--模块版本管理--> <Ssm05-common.version>1.0-SNAPSHOT</Ssm05-common.version> <Ssm05-model.version>1.0-SNAPSHOT</Ssm05-model.version> <Ssm05-dao.version>1.0-SNAPSHOT</Ssm05-dao.version> <Ssm05-service.version>1.0-SNAPSHOT</Ssm05-service.version> <Ssm05-webui.version>1.0-SNAPSHOT</Ssm05-webui.version> <!--通用部分--> <log4j.version>2.6.1</log4j.version> <junit.version>4.10</junit.version> <!--Spring--> <spring.version>4.3.0.RELEASE</spring.version> <aspectjweaver.version>1.8.9</aspectjweaver.version> <cglib.version>3.2.4</cglib.version> <!--mybatis--> <mybatis-spring.version>1.3.0</mybatis-spring.version> <mysql-connector-java.version>5.1.38</mysql-connector-java.version> <mybatis.version>3.4.1</mybatis.version> <c3p0.version>0.9.1.2</c3p0.version> <!--spring mvc--> <jstl.version>1.2</jstl.version> <servlet-api.version>3.0.1</servlet-api.version> <jsp-api.version>2.1</jsp-api.version> <hibernate.version>5.2.2.Final</hibernate.version> <commons-io.version>2.4</commons-io.version> <commons-fileupload.version>1.3.1</commons-fileupload.version> <freemarker.version>2.3.23</freemarker.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>com.tff.SSM05</groupId> <artifactId>Ssm05-common</artifactId> <version>${Ssm05-common.version}</version> </dependency> <dependency> <groupId>com.tff.SSM05</groupId> <artifactId>Ssm05-dao</artifactId> <version>${Ssm05-dao.version}</version> </dependency> <dependency> <groupId>com.tff.SSM05</groupId> <artifactId>Ssm05-model</artifactId> <version>${Ssm05-model.version}</version> </dependency> <dependency> <groupId>com.tff.SSM05</groupId> <artifactId>Ssm05-service</artifactId> <version>${Ssm05-service.version}</version> </dependency> <dependency> <groupId>com.tff.SSM05</groupId> <artifactId>Ssm05-webui</artifactId> <version>${Ssm05-webui.version}</version> </dependency> <!--jackson--> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <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-annotations</artifactId> <version>${jackson.version}</version> </dependency> <!--apache-commons--> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <!--log4j日志包 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>${log4j.version}</version> </dependency> <!-- JUnit单元测试工具 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> </dependency> <!--Spring框架核心库 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <!-- aspectJ AOP 织入器 --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectjweaver.version}</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>${cglib.version}</version> </dependency> <!--mybatis-spring适配器 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis-spring.version}</version> </dependency> <!--Spring java数据库访问包,在本例中主要用于提供数据源 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <!--mysql数据库驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql-connector-java.version}</version> </dependency> <!-- mybatis ORM框架 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <!--c3p0 连接池 --> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>${c3p0.version}</version> </dependency> <!-- Spring MVC --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <!-- JSTL --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> <!-- Servlet核心包 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet-api.version}</version> </dependency> <!--JSP --> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>${jsp-api.version}</version> </dependency> <!--JSR303 --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>${hibernate.version}</version> </dependency> <!--文件上传 --> <dependency> <groupId>commons-io</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> <!-- FreeMarker --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>${freemarker.version}</version> </dependency> </dependencies> </dependencyManagement> </project>
4.各模块添加依赖和插件
dao
<!--其他模块--> <dependencies> <dependency> <groupId>com.tff.SSM05</groupId> <artifactId>Ssm05-model</artifactId> </dependency> <dependency> <groupId>com.tff.SSM05</groupId> <artifactId>Ssm05-common</artifactId> </dependency> <!--插件--> <!--log4j日志包 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </dependency> <!-- JUnit单元测试工具 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <!--Spring框架核心库 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <!-- aspectJ AOP 织入器 --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> </dependency> <!--mybatis-spring适配器 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <!--Spring java数据库访问包,在本例中主要用于提供数据源 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <!--mysql数据库驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- mybatis ORM框架 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <!--c3p0 连接池 --> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> </dependency> </dependencies>
service
<!--其他模块--> <dependency> <groupId>com.tff.SSM05</groupId> <artifactId>Ssm05-dao</artifactId> </dependency> <!--插件-->
webui
<dependencies> <!--其他模块--> <dependency> <groupId>com.tff.SSM05</groupId> <artifactId>Ssm05-service</artifactId> </dependency> <!--插件--> <!-- Spring MVC --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <!-- JSTL --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <!-- Servlet核心包 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <!--JSP --> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> </dependency> <!--JSR303 --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies>
5.实体模块
因项目而异