首页 > 代码库 > ssm框架整合+maven项目创建
ssm框架整合+maven项目创建
在引入外部maven插件后就可以创建一个maven项目了,这篇文章主要介绍ssm框架的整合和如何创建一个maven项目
1、在开发工具的项目空白区单击右键,依次选择New、Other,会出现如下界面,选择Maven Project,每一步操作后出现的界面都会在下面的图中展示出来,跟着一步一步操作即可;
这样一个maven项目就创建完成了,结构如下如所示,该中结构仅支持jdk1.7及以上。这里只是有一个项目存在,里面并没有分层,我们所用的是ssm框架,需要在项目中搭建出包结构,在src/main/java这个目录下新建这样几个包:
(1) com.zhiliu.web(控制层:接受前台数据,进行页面跳转处理)
(2) com.zhiliu.service(业务层接口:处理相关的逻辑业务)
(3) com.zhiliu.service.impl(service接口的具体实现)
(4) com.zhiliu.dao(持久层:与处理数据库操作相关)
(5) com.zhiliu.bean(实体类:与数据库中的表对应)
在src/mian/resources这个目录下新建一个mapping和spring文件夹
mapping文件夹:存放dao中每个方法对应的sql,在这里配置,不用写dao的实现类daoimpl
spring文件夹:存放spring相关的配置文件
在src/test/java目录里面可以对照src/main/java这个里面建包结构,作为测试src/main/java这个目录下的各层方法的分层
完成以上步骤后,基本的项目结构就清楚了,接下来就是框架的整合了,配置各个层的配置文件,由于我们是使用maven来管理我们项目的架包的,我们首先需要添加架包的依赖,在pom.xml文件中
pom.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>com.zl</groupId> 5 <artifactId>study</artifactId> 6 <packaging>war</packaging> 7 <version>0.0.1-SNAPSHOT</version> 8 <name>study Maven Webapp</name> 9 <url>http://maven.apache.org</url> 10 11 <properties> 12 <!-- spring版本号 --> 13 <spring.version>4.2.2.RELEASE</spring.version> 14 <!-- mybatis版本号 --> 15 <mybatis.version>3.2.6</mybatis.version> 16 <!-- log4j日志文件管理包版本 --> 17 <slf4j.version>1.7.7</slf4j.version> 18 <log4j.version>1.2.17</log4j.version> 19 </properties> 20 21 22 <dependencies> 23 <!-- 单元测试 --> 24 <dependency> 25 <groupId>junit</groupId> 26 <artifactId>junit</artifactId> 27 <version>4.11</version> 28 </dependency> 29 30 <dependency> 31 <groupId>commons-fileupload</groupId> 32 <artifactId>commons-fileupload</artifactId> 33 <version>1.3.2</version> 34 </dependency> 35 36 <!-- 1.日志 --> 37 <!-- 实现slf4j接口并整合 --> 38 <dependency> 39 <groupId>org.slf4j</groupId> 40 <artifactId>slf4j-api</artifactId> 41 <version>1.7.7</version> 42 </dependency> 43 <dependency> 44 <groupId>ch.qos.logback</groupId> 45 <artifactId>logback-core</artifactId> 46 <version>1.1.3</version> 47 </dependency> 48 <dependency> 49 <groupId>ch.qos.logback</groupId> 50 <artifactId>logback-access</artifactId> 51 <version>1.1.3</version> 52 </dependency> 53 <dependency> 54 <groupId>ch.qos.logback</groupId> 55 <artifactId>logback-classic</artifactId> 56 <version>1.1.3</version> 57 </dependency> 58 59 <!-- 2.数据库 --> 60 <dependency> 61 <groupId>mysql</groupId> 62 <artifactId>mysql-connector-java</artifactId> 63 <version>5.1.37</version> 64 <scope>runtime</scope> 65 </dependency> 66 <dependency> 67 <groupId>c3p0</groupId> 68 <artifactId>c3p0</artifactId> 69 <version>0.9.1.2</version> 70 </dependency> 71 72 <!-- DAO: MyBatis --> 73 <dependency> 74 <groupId>org.mybatis</groupId> 75 <artifactId>mybatis</artifactId> 76 <version>3.3.0</version> 77 </dependency> 78 <dependency> 79 <groupId>org.mybatis</groupId> 80 <artifactId>mybatis-spring</artifactId> 81 <version>1.2.3</version> 82 </dependency> 83 84 <!-- 3.Servlet web --> 85 <dependency> 86 <groupId>taglibs</groupId> 87 <artifactId>standard</artifactId> 88 <version>1.1.2</version> 89 </dependency> 90 <dependency> 91 <groupId>jstl</groupId> 92 <artifactId>jstl</artifactId> 93 <version>1.2</version> 94 </dependency> 95 <dependency> 96 <groupId>com.fasterxml.jackson.core</groupId> 97 <artifactId>jackson-databind</artifactId> 98 <version>2.5.4</version> 99 </dependency> 100 <dependency> 101 <groupId>javax.servlet</groupId> 102 <artifactId>javax.servlet-api</artifactId> 103 <version>3.1.0</version> 104 </dependency> 105 106 <!-- 4.Spring --> 107 <!-- 1)Spring核心 --> 108 <dependency> 109 <groupId>org.springframework</groupId> 110 <artifactId>spring-core</artifactId> 111 <version>4.2.2.RELEASE</version> 112 </dependency> 113 <dependency> 114 <groupId>org.springframework</groupId> 115 <artifactId>spring-beans</artifactId> 116 <version>4.2.2.RELEASE</version> 117 </dependency> 118 <dependency> 119 <groupId>org.springframework</groupId> 120 <artifactId>spring-context</artifactId> 121 <version>4.2.2.RELEASE</version> 122 </dependency> 123 <!-- 2)Spring DAO层 --> 124 <dependency> 125 <groupId>org.springframework</groupId> 126 <artifactId>spring-jdbc</artifactId> 127 <version>4.2.2.RELEASE</version> 128 </dependency> 129 <dependency> 130 <groupId>org.springframework</groupId> 131 <artifactId>spring-tx</artifactId> 132 <version>4.2.2.RELEASE</version> 133 </dependency> 134 <!-- 3)Spring web --> 135 <dependency> 136 <groupId>org.springframework</groupId> 137 <artifactId>spring-web</artifactId> 138 <version>4.2.2.RELEASE</version> 139 </dependency> 140 <dependency> 141 <groupId>org.springframework</groupId> 142 <artifactId>spring-webmvc</artifactId> 143 <version>4.2.2.RELEASE</version> 144 </dependency> 145 <!-- 4)Spring test --> 146 <dependency> 147 <groupId>org.springframework</groupId> 148 <artifactId>spring-test</artifactId> 149 <version>4.2.2.RELEASE</version> 150 </dependency> 151 152 <!-- redis客户端:Jedis --> 153 <dependency> 154 <groupId>redis.clients</groupId> 155 <artifactId>jedis</artifactId> 156 <version>2.7.3</version> 157 </dependency> 158 <dependency> 159 <groupId>com.dyuproject.protostuff</groupId> 160 <artifactId>protostuff-core</artifactId> 161 <version>1.0.8</version> 162 </dependency> 163 <dependency> 164 <groupId>com.dyuproject.protostuff</groupId> 165 <artifactId>protostuff-runtime</artifactId> 166 <version>1.0.8</version> 167 </dependency> 168 169 <!-- Map工具类 --> 170 <dependency> 171 <groupId>commons-collections</groupId> 172 <artifactId>commons-collections</artifactId> 173 <version>3.2</version> 174 </dependency> 175 176 <dependency> 177 <groupId>net.sf.json-lib</groupId> 178 <artifactId>json-lib</artifactId> 179 <version>2.4</version> 180 <classifier>jdk15</classifier> 181 </dependency> 182 </dependencies> 183 184 <build> 185 <finalName>study</finalName> 186 </build> 187 </project>
至此maven项目创建完成,接下来就是整合各个配置文件了,配置文件的代码片段里都写了注释,关键部分需要根据自己的项目进行修改
ssm框架整合+maven项目创建