使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

时间:2021-03-04 03:47:51

一、创建一个空的项目作为存放整个项目的路径

1、选择 File——>new——>Project ——>Empty Project

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

2、WorkspaceforTest为项目存放文件夹。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

 

 二、maven继承:创建父-子项目,聚合工程

比如整个项目。以一个项目来演示。

       |--e3-parent:父工程,打包方式pom,管理jar包的版本号。项目中所有工程都应该继承父工程。

  |--e3-common:通用的工具类通用的pojo。打包方式jar

  |--e3-manager:服务层工程。聚合工程。Pom工程

    |--e3-manager-dao:打包方式jar

    |--e3-manager-pojo:打包方式jar

    |--e3-manager-interface:打包方式jar

    |--e3-manager-service:打包方式:jar

       |--e3-manager-web:表现层工程。打包方式war

1、创建maven父工程 e3-parent

File——>New ——>Module.. ——>Maven

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

2、GroupId一般为公司域名倒过来写。ArtifactId写工程名字。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

3、Maven home directory 在这里我选择自己安装的maven,还有User settings file 选择好本地仓库。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 4、注意下e3-parent的项目路径,在WorkspaceforTest下面。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

5、在e3-parent的pom.xml文件下添加<packaging>pom</packaging>,e3-parent是打成pom文件的

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

 6、就可以pom文件添加各种依赖了。在这里我的e3-parent的pom.xml文件如下。

e3-parent的pom.xml
使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
  1 <?xml version="1.0" encoding="UTF-8"?>
  2 
  3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5   <modelVersion>4.0.0</modelVersion>
  6 
  7   <groupId>e3.mall</groupId>
  8   <artifactId>e3-parent</artifactId>
  9   <version>1.0-SNAPSHOT</version>
 10 
 11   <name>e3-parent</name>
 12   <packaging>pom</packaging>
 13   <!-- 集中定义依赖版本号 -->
 14   <properties>
 15     <junit.version>4.12</junit.version>
 16     <spring.version>4.2.4.RELEASE</spring.version>
 17     <mybatis.version>3.2.8</mybatis.version>
 18     <mybatis.spring.version>1.2.2</mybatis.spring.version>
 19     <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
 20     <mysql.version>5.1.46</mysql.version>
 21     <slf4j.version>1.6.4</slf4j.version>
 22     <jackson.version>2.4.2</jackson.version>
 23     <druid.version>1.0.9</druid.version>
 24     <httpclient.version>4.3.5</httpclient.version>
 25     <jstl.version>1.2</jstl.version>
 26     <servlet-api.version>2.5</servlet-api.version>
 27     <jsp-api.version>2.0</jsp-api.version>
 28     <joda-time.version>2.5</joda-time.version>
 29     <commons-lang3.version>3.3.2</commons-lang3.version>
 30     <commons-io.version>1.3.2</commons-io.version>
 31     <commons-net.version>3.3</commons-net.version>
 32     <pagehelper.version>3.4.2-fix</pagehelper.version>
 33     <jsqlparser.version>0.9.1</jsqlparser.version>
 34     <commons-fileupload.version>1.3.1</commons-fileupload.version>
 35     <jedis.version>2.7.2</jedis.version>
 36     <solrj.version>4.10.3</solrj.version>
 37     <dubbo.version>2.5.3</dubbo.version>
 38     <zookeeper.version>3.4.7</zookeeper.version>
 39     <zkclient.version>0.1</zkclient.version>
 40     <activemq.version>5.11.2</activemq.version>
 41     <freemarker.version>2.3.23</freemarker.version>
 42     <quartz.version>2.2.2</quartz.version>
 43   </properties>
 44   <dependencyManagement>
 45     <dependencies>
 46       <!-- 时间操作组件 -->
 47       <dependency>
 48         <groupId>joda-time</groupId>
 49         <artifactId>joda-time</artifactId>
 50         <version>${joda-time.version}</version>
 51       </dependency>
 52       <!-- Apache工具组件 -->
 53       <dependency>
 54         <groupId>org.apache.commons</groupId>
 55         <artifactId>commons-lang3</artifactId>
 56         <version>${commons-lang3.version}</version>
 57       </dependency>
 58       <dependency>
 59         <groupId>org.apache.commons</groupId>
 60         <artifactId>commons-io</artifactId>
 61         <version>${commons-io.version}</version>
 62       </dependency>
 63       <dependency>
 64         <groupId>commons-net</groupId>
 65         <artifactId>commons-net</artifactId>
 66         <version>${commons-net.version}</version>
 67       </dependency>
 68       <!-- Jackson Json处理工具包 -->
 69       <dependency>
 70         <groupId>com.fasterxml.jackson.core</groupId>
 71         <artifactId>jackson-databind</artifactId>
 72         <version>${jackson.version}</version>
 73       </dependency>
 74       <!-- httpclient -->
 75       <dependency>
 76         <groupId>org.apache.httpcomponents</groupId>
 77         <artifactId>httpclient</artifactId>
 78         <version>${httpclient.version}</version>
 79       </dependency>
 80       <!-- quartz任务调度框架 -->
 81       <dependency>
 82         <groupId>org.quartz-scheduler</groupId>
 83         <artifactId>quartz</artifactId>
 84         <version>${quartz.version}</version>
 85       </dependency>
 86       <!-- 单元测试 -->
 87       <dependency>
 88         <groupId>junit</groupId>
 89         <artifactId>junit</artifactId>
 90         <version>${junit.version}</version>
 91         <scope>test</scope>
 92       </dependency>
 93       <!-- 日志处理 -->
 94       <dependency>
 95         <groupId>org.slf4j</groupId>
 96         <artifactId>slf4j-log4j12</artifactId>
 97         <version>${slf4j.version}</version>
 98       </dependency>
 99       <!-- Mybatis -->
100       <dependency>
101         <groupId>org.mybatis</groupId>
102         <artifactId>mybatis</artifactId>
103         <version>${mybatis.version}</version>
104       </dependency>
105       <dependency>
106         <groupId>org.mybatis</groupId>
107         <artifactId>mybatis-spring</artifactId>
108         <version>${mybatis.spring.version}</version>
109       </dependency>
110       <dependency>
111         <groupId>com.github.miemiedev</groupId>
112         <artifactId>mybatis-paginator</artifactId>
113         <version>${mybatis.paginator.version}</version>
114       </dependency>
115       <dependency>
116         <groupId>com.github.pagehelper</groupId>
117         <artifactId>pagehelper</artifactId>
118         <version>${pagehelper.version}</version>
119       </dependency>
120       <!-- MySql -->
121       <dependency>
122         <groupId>mysql</groupId>
123         <artifactId>mysql-connector-java</artifactId>
124         <version>${mysql.version}</version>
125       </dependency>
126       <!-- 连接池 -->
127       <dependency>
128         <groupId>com.alibaba</groupId>
129         <artifactId>druid</artifactId>
130         <version>${druid.version}</version>
131       </dependency>
132       <!-- Spring -->
133       <dependency>
134         <groupId>org.springframework</groupId>
135         <artifactId>spring-context</artifactId>
136         <version>${spring.version}</version>
137       </dependency>
138       <dependency>
139         <groupId>org.springframework</groupId>
140         <artifactId>spring-beans</artifactId>
141         <version>${spring.version}</version>
142       </dependency>
143       <dependency>
144         <groupId>org.springframework</groupId>
145         <artifactId>spring-webmvc</artifactId>
146         <version>${spring.version}</version>
147       </dependency>
148       <dependency>
149         <groupId>org.springframework</groupId>
150         <artifactId>spring-jdbc</artifactId>
151         <version>${spring.version}</version>
152       </dependency>
153       <dependency>
154         <groupId>org.springframework</groupId>
155         <artifactId>spring-aspects</artifactId>
156         <version>${spring.version}</version>
157       </dependency>
158       <dependency>
159         <groupId>org.springframework</groupId>
160         <artifactId>spring-jms</artifactId>
161         <version>${spring.version}</version>
162       </dependency>
163       <dependency>
164         <groupId>org.springframework</groupId>
165         <artifactId>spring-context-support</artifactId>
166         <version>${spring.version}</version>
167       </dependency>
168       <!-- JSP相关 -->
169       <dependency>
170         <groupId>jstl</groupId>
171         <artifactId>jstl</artifactId>
172         <version>${jstl.version}</version>
173       </dependency>
174       <dependency>
175         <groupId>javax.servlet</groupId>
176         <artifactId>servlet-api</artifactId>
177         <version>${servlet-api.version}</version>
178         <scope>provided</scope>
179       </dependency>
180       <dependency>
181         <groupId>javax.servlet</groupId>
182         <artifactId>jsp-api</artifactId>
183         <version>${jsp-api.version}</version>
184         <scope>provided</scope>
185       </dependency>
186       <!-- 文件上传组件 -->
187       <dependency>
188         <groupId>commons-fileupload</groupId>
189         <artifactId>commons-fileupload</artifactId>
190         <version>${commons-fileupload.version}</version>
191       </dependency>
192       <!-- Redis客户端 -->
193       <dependency>
194         <groupId>redis.clients</groupId>
195         <artifactId>jedis</artifactId>
196         <version>${jedis.version}</version>
197       </dependency>
198       <!-- solr客户端 -->
199       <dependency>
200         <groupId>org.apache.solr</groupId>
201         <artifactId>solr-solrj</artifactId>
202         <version>${solrj.version}</version>
203       </dependency>
204       <!-- dubbo相关 -->
205       <dependency>
206         <groupId>com.alibaba</groupId>
207         <artifactId>dubbo</artifactId>
208         <version>${dubbo.version}</version>
209       </dependency>
210       <dependency>
211         <groupId>org.apache.zookeeper</groupId>
212         <artifactId>zookeeper</artifactId>
213         <version>${zookeeper.version}</version>
214       </dependency>
215       <dependency>
216         <groupId>com.github.sgroschupf</groupId>
217         <artifactId>zkclient</artifactId>
218         <version>${zkclient.version}</version>
219       </dependency>
220       <dependency>
221         <groupId>org.apache.activemq</groupId>
222         <artifactId>activemq-all</artifactId>
223         <version>${activemq.version}</version>
224       </dependency>
225       <dependency>
226         <groupId>org.freemarker</groupId>
227         <artifactId>freemarker</artifactId>
228         <version>${freemarker.version}</version>
229       </dependency>
230 
231     </dependencies>
232   </dependencyManagement>
233 
234   <build>
235     <finalName>${project.artifactId}</finalName>
236     <plugins>
237       <!-- 资源文件拷贝插件 -->
238       <plugin>
239         <groupId>org.apache.maven.plugins</groupId>
240         <artifactId>maven-resources-plugin</artifactId>
241         <version>2.7</version>
242         <configuration>
243           <encoding>UTF-8</encoding>
244         </configuration>
245       </plugin>
246       <!-- java编译插件 -->
247       <plugin>
248         <groupId>org.apache.maven.plugins</groupId>
249         <artifactId>maven-compiler-plugin</artifactId>
250         <version>3.2</version>
251         <configuration>
252           <source>1.7</source>
253           <target>1.7</target>
254           <encoding>UTF-8</encoding>
255         </configuration>
256       </plugin>
257     </plugins>
258     <pluginManagement>
259       <plugins>
260         <!-- 配置Tomcat插件 -->
261         <plugin>
262           <groupId>org.apache.tomcat.maven</groupId>
263           <artifactId>tomcat7-maven-plugin</artifactId>
264           <version>2.2</version>
265         </plugin>
266       </plugins>
267     </pluginManagement>
268   </build>
269 
270 </project>
View Code

 

 

7、创建e3-common,e3-common继承父工程parent。而且为了与eclipse下面一样一种好看,common工程的目录也是在WorkspaceforTest目录下,但是是继承了parent工程

File——>New——>module——>Maven

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

8、common工程也是在WorkspaceforTest目录下的,所以要在Add as module to选项中选择None,如下图所示

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 9、Parent 中选择继承的父工程e3-parent,如下图所示,再写好ArtifactId.

 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

10、选择maven,如果没有发生改变,就可以直接下一步。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

11、注意一下路径,是在WorkspaceforTest下面。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

12、再在pom.xml下面添加<packaging>jar</packaging>,如下图所示。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

 在这个项目的pom文件如下代码所示。

e3-common的 pom.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>e3-parent</artifactId>
 7         <groupId>e3.mall</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9         <relativePath>../e3-parent/pom.xml</relativePath>
10     </parent>
11     <modelVersion>4.0.0</modelVersion>
12 
13     <artifactId>e3-common</artifactId>
14     <packaging>jar</packaging>
15 
16     <name>e3-common</name>
17     <dependencies>
18         <!-- 时间操作组件 -->
19         <dependency>
20             <groupId>joda-time</groupId>
21             <artifactId>joda-time</artifactId>
22         </dependency>
23         <!-- Apache工具组件 -->
24         <dependency>
25             <groupId>org.apache.commons</groupId>
26             <artifactId>commons-lang3</artifactId>
27         </dependency>
28         <dependency>
29             <groupId>org.apache.commons</groupId>
30             <artifactId>commons-io</artifactId>
31         </dependency>
32         <dependency>
33             <groupId>commons-net</groupId>
34             <artifactId>commons-net</artifactId>
35         </dependency>
36         <!-- Jackson Json处理工具包 -->
37         <dependency>
38             <groupId>com.fasterxml.jackson.core</groupId>
39             <artifactId>jackson-databind</artifactId>
40         </dependency>
41         <!-- httpclient -->
42         <dependency>
43             <groupId>org.apache.httpcomponents</groupId>
44             <artifactId>httpclient</artifactId>
45         </dependency>
46         <!-- quartz任务调度框架 -->
47         <dependency>
48             <groupId>org.quartz-scheduler</groupId>
49             <artifactId>quartz</artifactId>
50         </dependency>
51         <!-- 单元测试 -->
52         <dependency>
53             <groupId>junit</groupId>
54             <artifactId>junit</artifactId>
55             <scope>test</scope>
56         </dependency>
57         <!-- 日志处理 -->
58         <dependency>
59             <groupId>org.slf4j</groupId>
60             <artifactId>slf4j-log4j12</artifactId>
61         </dependency>
62     </dependencies>
63 
64 </project>
View Code

 

 

13、创建manager工程,与common工程的方法一样。

File——>New——>module——>Maven

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 14、再在pom.xml下面添加<packaging>pom</packaging>,如下图所示。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

e3-common的 pom.xml文件

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>e3-parent</artifactId>
 7         <groupId>e3.mall</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9         <relativePath>../e3-parent/pom.xml</relativePath>
10     </parent>
11     <modelVersion>4.0.0</modelVersion>
12 
13     <artifactId>e3-manager</artifactId>
14     <packaging>pom</packaging>
15     <modules>
16         <module>e3-manager-pojo</module>
17         <module>e3-manager-dao</module>
18         <module>e3-manager-interface</module>
19         <module>e3-manager-service</module>
20         <module>e3-manager-web</module>
21     </modules>
22     <dependencies>
23         <dependency>
24             <artifactId>e3-common</artifactId>
25             <groupId>e3.mall</groupId>
26             <version>1.0-SNAPSHOT</version>
27         </dependency>
28     </dependencies>
29 
30     <build>
31         <!-- 配置插件 -->
32         <plugins>
33             <plugin>
34                 <groupId>org.apache.tomcat.maven</groupId>
35                 <artifactId>tomcat7-maven-plugin</artifactId>
36                 <configuration>
37                     <port>8080</port>
38                     <path>/</path>
39                 </configuration>
40             </plugin>
41         </plugins>
42     </build>
43 </project>
View Code

 

 

 

15,来开始创建e3-manager-pojo、e3-manager-dao、e3-manager-interface、e3-manager-service,这四个工程最终都是打成jar包的,创建过程都是一样的,下面就只写出一个工程的创建过程。

以e3-manager-pojo为例。

16、选中e3-manager——>右击鼠标——>New——Module,因为e3-manager-pojo是e3-manager的子工程。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

17、再在pom.xml下面添加<packaging>pom</packaging>,如下图所示。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

18、e3-manager-pojo、e3-manager-dao、e3-manager-interface、e3-manager-service,这四个工程都是这样创建。

19、e3-manager-pojo、e3-manager-dao、e3-manager-interface、e3-manager-service,这四个工程的pom.xml文件。

e3-manager-pojo 的pom.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>e3-manager</artifactId>
 7         <groupId>e3.mall</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9     </parent>
10     <modelVersion>4.0.0</modelVersion>
11 
12     <artifactId>e3-manager-pojo</artifactId>
13     <packaging>jar</packaging>
14     <name>e3-manager-pojo</name>
15 
16 </project>
View Code

 

e3-manager-dao 的pom.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>e3-manager</artifactId>
 7         <groupId>e3.mall</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9     </parent>
10     <modelVersion>4.0.0</modelVersion>
11 
12     <artifactId>e3-manager-dao</artifactId>
13     <packaging>jar</packaging>
14 
15     <name>e3-manager-dao</name>
16     <dependencies>
17         <dependency>
18             <groupId>e3.mall</groupId>
19             <artifactId>e3-manager-pojo</artifactId>
20             <version>1.0-SNAPSHOT</version>
21         </dependency>
22         <!-- 添加对mybatis的依赖 -->
23         <dependency>
24             <groupId>org.mybatis</groupId>
25             <artifactId>mybatis</artifactId>
26         </dependency>
27         <dependency>
28             <groupId>org.mybatis</groupId>
29             <artifactId>mybatis-spring</artifactId>
30         </dependency>
31         <dependency>
32             <groupId>com.github.miemiedev</groupId>
33             <artifactId>mybatis-paginator</artifactId>
34         </dependency>
35         <dependency>
36             <groupId>com.github.pagehelper</groupId>
37             <artifactId>pagehelper</artifactId>
38         </dependency>
39         <!-- MySql -->
40         <dependency>
41             <groupId>mysql</groupId>
42             <artifactId>mysql-connector-java</artifactId>
43         </dependency>
44         <!-- 连接池 -->
45         <dependency>
46             <groupId>com.alibaba</groupId>
47             <artifactId>druid</artifactId>
48         </dependency>
49 
50     </dependencies>
51     <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
52     <build>
53         <resources>
54             <resource>
55                 <directory>src/main/java</directory>
56                 <includes>
57                     <include>**/*.properties</include>
58                     <include>**/*.xml</include>
59                 </includes>
60                 <filtering>false</filtering>
61             </resource>
62         </resources>
63     </build>
64 </project>
View Code

 

 e3-manager-interface 的pom.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>e3-manager</artifactId>
 7         <groupId>e3.mall</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9     </parent>
10     <modelVersion>4.0.0</modelVersion>
11 
12     <artifactId>e3-manager-interface</artifactId>
13     <packaging>jar</packaging>
14     <name>e3-manager-interface</name>
15     <dependencies>
16         <dependency>
17             <groupId>e3.mall</groupId>
18             <artifactId>e3-manager-pojo</artifactId>
19             <version>1.0-SNAPSHOT</version>
20         </dependency>
21     </dependencies>
22 </project>
View Code

 

 e3-manager-servicer 的pom.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>e3-manager</artifactId>
 7         <groupId>e3.mall</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9     </parent>
10     <modelVersion>4.0.0</modelVersion>
11 
12     <artifactId>e3-manager-service</artifactId>
13 
14     <name>e3-manager-service</name>
15    <packaging>jar</packaging>
16 
17     <dependencies>
18         <dependency>
19             <groupId>e3.mall</groupId>
20             <artifactId>e3-manager-dao</artifactId>
21             <version>1.0-SNAPSHOT</version>
22         </dependency>
23         <dependency>
24             <groupId>e3.mall</groupId>
25             <artifactId>e3-manager-interface</artifactId>
26             <version>1.0-SNAPSHOT</version>
27         </dependency>
28         <!-- spring的依赖 -->
29         <!-- Spring -->
30         <dependency>
31             <groupId>org.springframework</groupId>
32             <artifactId>spring-context</artifactId>
33         </dependency>
34         <dependency>
35             <groupId>org.springframework</groupId>
36             <artifactId>spring-beans</artifactId>
37         </dependency>
38         <dependency>
39             <groupId>org.springframework</groupId>
40             <artifactId>spring-webmvc</artifactId>
41         </dependency>
42         <dependency>
43             <groupId>org.springframework</groupId>
44             <artifactId>spring-jdbc</artifactId>
45         </dependency>
46         <dependency>
47             <groupId>org.springframework</groupId>
48             <artifactId>spring-aspects</artifactId>
49         </dependency>
50         <dependency>
51             <groupId>org.springframework</groupId>
52             <artifactId>spring-jms</artifactId>
53         </dependency>
54         <dependency>
55             <groupId>org.springframework</groupId>
56             <artifactId>spring-context-support</artifactId>
57         </dependency>
58 
59     </dependencies>
60 </project>
View Code

 

 

20、最后创建e3-manager-web工程,创建过程都与上面的四个过程一样。只是有一个地方需要注意,下面的截图会提示。

选中e3-manager——>右击鼠标——>New——Module,因为e3-manager-web是e3-manager的子工程。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

只是下面需要注意一下。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 21、再在pom.xml下面添加<packaging>war</packaging>,如下图所示。

 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

22、e3-manager-web的pom.xml文件

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>e3-parent</artifactId>
 7         <groupId>e3.mall</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9         <relativePath>../e3-parent/pom.xml</relativePath>
10     </parent>
11     <modelVersion>4.0.0</modelVersion>
12 
13     <artifactId>e3-manager</artifactId>
14     <packaging>pom</packaging>
15     <modules>
16         <module>e3-manager-pojo</module>
17         <module>e3-manager-dao</module>
18         <module>e3-manager-interface</module>
19         <module>e3-manager-service</module>
20         <module>e3-manager-web</module>
21     </modules>
22     <dependencies>
23         <dependency>
24             <artifactId>e3-common</artifactId>
25             <groupId>e3.mall</groupId>
26             <version>1.0-SNAPSHOT</version>
27         </dependency>
28     </dependencies>
29 
30     <build>
31         <!-- 配置插件 -->
32         <plugins>
33             <plugin>
34                 <groupId>org.apache.tomcat.maven</groupId>
35                 <artifactId>tomcat7-maven-plugin</artifactId>
36                 <configuration>
37                     <port>8080</port>
38                     <path>/</path>
39                 </configuration>
40             </plugin>
41         </plugins>
42     </build>
43 </project>
View Code

 

 

 23、好了。到此maven聚合工程创建完成。

 

三、maven工程下创建resources文件夹

步骤:File——>Project Struture——>Modules——>maven工程,如果没有maven工程就点+号来添加

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

选择到创建resources文件夹的路径,比如图上的选择到main,右击鼠标,选择New Folder新建文件夹resources

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

再选择resources,右击鼠标选择Resources,可以看到resources文件夹的图标和之前不一样了,就是这样创建一个resources文件夹。再点Ok保存退出 。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

 很明图标都不一样了。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

四、整合ssm框架

直接看项目路径,直接上代码,不懂ssm框架整合的可以百度学习下。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

SqlMapConfig.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

</configuration>
View Code

 

db.properties

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/e3mall?charactherEncoding=utf-8
jdbc.username=root
jdbc.password=*****
View Code

 

applicationContext-Dao.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       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-4.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
    <!--数据库连接池-->
    <!--加载配置文件-->
    <context:property-placeholder location="classpath:properties/db.properties"></context:property-placeholder>
    <!--数据库连接池-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
        <property name="maxActive" value="10"></property>
        <property name="minIdle" value="5"></property>
    </bean>
    <!--让spring管理sqlsessionFactory,使用mybatis和spring整合包中的-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--数据库连接池-->
        <property name="dataSource" ref="dataSource"></property>
        <!--加载mybatis全局配置文件-->
        <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property>

    </bean>

    <!--自动扫描mapper-->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.e3mall.mapper"></property>
    </bean>
</beans>
View Code

 

applicationContext-service.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       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-4.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">


    <context:component-scan base-package="cn.e3mall.service"></context:component-scan>
</beans>
View Code

 

applicationContext-trans.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       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-4.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
    <!--事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--数据源-->
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!--通知-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="save*" propagation="REQUIRED"/>
            <tx:method name="insert*" propagation="REQUIRED"/>
            <tx:method name="add*" propagation="REQUIRED"/>
            <tx:method name="create*" propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
        </tx:attributes>

    </tx:advice>
    <!--切面-->
    <aop:config>
        <aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.e3mall.mapper.*.*(..))"></aop:advisor>
    </aop:config>
</beans>
View Code

 

springmvc.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
       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-4.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
    <!--扫描controller-->
    <context:component-scan base-package="cn.e3mall.controller"/>
    <!--配置适配器映射器-->
    <mvc:annotation-driven></mvc:annotation-driven>

    <!--配置前端控制器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>
View Code

 

web.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">
    <display-name>e3-manager</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    
    <!--加载spring容器-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/applicationContext-*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!--配置post提交乱码-->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!--spring前端控制器-->
    <servlet>
        <servlet-name>e3-manager</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/springmvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>e3-manager</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
View Code

 

 TbItem.class

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
  1 package cn.e3mall.pojo;
  2 
  3 import java.util.Date;
  4 
  5 public class TbItem {
  6     private Long id;
  7 
  8     private String title;
  9 
 10     private String sellPoint;
 11 
 12     private Long price;
 13 
 14     private Integer num;
 15 
 16     private String barcode;
 17 
 18     private String image;
 19 
 20     private Long cid;
 21 
 22     private Byte status;
 23 
 24     private Date created;
 25 
 26     private Date updated;
 27 
 28     public Long getId() {
 29         return id;
 30     }
 31 
 32     public void setId(Long id) {
 33         this.id = id;
 34     }
 35 
 36     public String getTitle() {
 37         return title;
 38     }
 39 
 40     public void setTitle(String title) {
 41         this.title = title == null ? null : title.trim();
 42     }
 43 
 44     public String getSellPoint() {
 45         return sellPoint;
 46     }
 47 
 48     public void setSellPoint(String sellPoint) {
 49         this.sellPoint = sellPoint == null ? null : sellPoint.trim();
 50     }
 51 
 52     public Long getPrice() {
 53         return price;
 54     }
 55 
 56     public void setPrice(Long price) {
 57         this.price = price;
 58     }
 59 
 60     public Integer getNum() {
 61         return num;
 62     }
 63 
 64     public void setNum(Integer num) {
 65         this.num = num;
 66     }
 67 
 68     public String getBarcode() {
 69         return barcode;
 70     }
 71 
 72     public void setBarcode(String barcode) {
 73         this.barcode = barcode == null ? null : barcode.trim();
 74     }
 75 
 76     public String getImage() {
 77         return image;
 78     }
 79 
 80     public void setImage(String image) {
 81         this.image = image == null ? null : image.trim();
 82     }
 83 
 84     public Long getCid() {
 85         return cid;
 86     }
 87 
 88     public void setCid(Long cid) {
 89         this.cid = cid;
 90     }
 91 
 92     public Byte getStatus() {
 93         return status;
 94     }
 95 
 96     public void setStatus(Byte status) {
 97         this.status = status;
 98     }
 99 
100     public Date getCreated() {
101         return created;
102     }
103 
104     public void setCreated(Date created) {
105         this.created = created;
106     }
107 
108     public Date getUpdated() {
109         return updated;
110     }
111 
112     public void setUpdated(Date updated) {
113         this.updated = updated;
114     }
115 }
View Code

 

TbItemMapper.class  接口

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 package cn.e3mall.mapper;
 2 
 3 import cn.e3mall.pojo.TbItem;
 4 import cn.e3mall.pojo.TbItemExample;
 5 import java.util.List;
 6 import org.apache.ibatis.annotations.Param;
 7 
 8 public interface TbItemMapper {
 9     int countByExample(TbItemExample example);
10 
11     int deleteByExample(TbItemExample example);
12 
13     int deleteByPrimaryKey(Long id);
14 
15     int insert(TbItem record);
16 
17     int insertSelective(TbItem record);
18 
19     List<TbItem> selectByExample(TbItemExample example);
20 
21     TbItem selectByPrimaryKey(Long id);
22 
23     int updateByExampleSelective(@Param("record") TbItem record, @Param("example") TbItemExample example);
24 
25     int updateByExample(@Param("record") TbItem record, @Param("example") TbItemExample example);
26 
27     int updateByPrimaryKeySelective(TbItem record);
28 
29     int updateByPrimaryKey(TbItem record);
30 }
View Code

 

TbItemMapper.xml

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.e3mall.mapper.TbItemMapper" >
  <resultMap id="BaseResultMap" type="cn.e3mall.pojo.TbItem" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="title" property="title" jdbcType="VARCHAR" />
    <result column="sell_point" property="sellPoint" jdbcType="VARCHAR" />
    <result column="price" property="price" jdbcType="BIGINT" />
    <result column="num" property="num" jdbcType="INTEGER" />
    <result column="barcode" property="barcode" jdbcType="VARCHAR" />
    <result column="image" property="image" jdbcType="VARCHAR" />
    <result column="cid" property="cid" jdbcType="BIGINT" />
    <result column="status" property="status" jdbcType="TINYINT" />
    <result column="created" property="created" jdbcType="TIMESTAMP" />
    <result column="updated" property="updated" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    id, title, sell_point, price, num, barcode, image, cid, status, created, updated
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="cn.e3mall.pojo.TbItemExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from tb_item
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from tb_item
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from tb_item
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="cn.e3mall.pojo.TbItemExample" >
    delete from tb_item
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="cn.e3mall.pojo.TbItem" >
    insert into tb_item (id, title, sell_point, 
      price, num, barcode, 
      image, cid, status, 
      created, updated)
    values (#{id,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR}, #{sellPoint,jdbcType=VARCHAR}, 
      #{price,jdbcType=BIGINT}, #{num,jdbcType=INTEGER}, #{barcode,jdbcType=VARCHAR}, 
      #{image,jdbcType=VARCHAR}, #{cid,jdbcType=BIGINT}, #{status,jdbcType=TINYINT}, 
      #{created,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="cn.e3mall.pojo.TbItem" >
    insert into tb_item
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="title != null" >
        title,
      </if>
      <if test="sellPoint != null" >
        sell_point,
      </if>
      <if test="price != null" >
        price,
      </if>
      <if test="num != null" >
        num,
      </if>
      <if test="barcode != null" >
        barcode,
      </if>
      <if test="image != null" >
        image,
      </if>
      <if test="cid != null" >
        cid,
      </if>
      <if test="status != null" >
        status,
      </if>
      <if test="created != null" >
        created,
      </if>
      <if test="updated != null" >
        updated,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="title != null" >
        #{title,jdbcType=VARCHAR},
      </if>
      <if test="sellPoint != null" >
        #{sellPoint,jdbcType=VARCHAR},
      </if>
      <if test="price != null" >
        #{price,jdbcType=BIGINT},
      </if>
      <if test="num != null" >
        #{num,jdbcType=INTEGER},
      </if>
      <if test="barcode != null" >
        #{barcode,jdbcType=VARCHAR},
      </if>
      <if test="image != null" >
        #{image,jdbcType=VARCHAR},
      </if>
      <if test="cid != null" >
        #{cid,jdbcType=BIGINT},
      </if>
      <if test="status != null" >
        #{status,jdbcType=TINYINT},
      </if>
      <if test="created != null" >
        #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="updated != null" >
        #{updated,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="cn.e3mall.pojo.TbItemExample" resultType="java.lang.Integer" >
    select count(*) from tb_item
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update tb_item
    <set >
      <if test="record.id != null" >
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.title != null" >
        title = #{record.title,jdbcType=VARCHAR},
      </if>
      <if test="record.sellPoint != null" >
        sell_point = #{record.sellPoint,jdbcType=VARCHAR},
      </if>
      <if test="record.price != null" >
        price = #{record.price,jdbcType=BIGINT},
      </if>
      <if test="record.num != null" >
        num = #{record.num,jdbcType=INTEGER},
      </if>
      <if test="record.barcode != null" >
        barcode = #{record.barcode,jdbcType=VARCHAR},
      </if>
      <if test="record.image != null" >
        image = #{record.image,jdbcType=VARCHAR},
      </if>
      <if test="record.cid != null" >
        cid = #{record.cid,jdbcType=BIGINT},
      </if>
      <if test="record.status != null" >
        status = #{record.status,jdbcType=TINYINT},
      </if>
      <if test="record.created != null" >
        created = #{record.created,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updated != null" >
        updated = #{record.updated,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update tb_item
    set id = #{record.id,jdbcType=BIGINT},
      title = #{record.title,jdbcType=VARCHAR},
      sell_point = #{record.sellPoint,jdbcType=VARCHAR},
      price = #{record.price,jdbcType=BIGINT},
      num = #{record.num,jdbcType=INTEGER},
      barcode = #{record.barcode,jdbcType=VARCHAR},
      image = #{record.image,jdbcType=VARCHAR},
      cid = #{record.cid,jdbcType=BIGINT},
      status = #{record.status,jdbcType=TINYINT},
      created = #{record.created,jdbcType=TIMESTAMP},
      updated = #{record.updated,jdbcType=TIMESTAMP}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="cn.e3mall.pojo.TbItem" >
    update tb_item
    <set >
      <if test="title != null" >
        title = #{title,jdbcType=VARCHAR},
      </if>
      <if test="sellPoint != null" >
        sell_point = #{sellPoint,jdbcType=VARCHAR},
      </if>
      <if test="price != null" >
        price = #{price,jdbcType=BIGINT},
      </if>
      <if test="num != null" >
        num = #{num,jdbcType=INTEGER},
      </if>
      <if test="barcode != null" >
        barcode = #{barcode,jdbcType=VARCHAR},
      </if>
      <if test="image != null" >
        image = #{image,jdbcType=VARCHAR},
      </if>
      <if test="cid != null" >
        cid = #{cid,jdbcType=BIGINT},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=TINYINT},
      </if>
      <if test="created != null" >
        created = #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="updated != null" >
        updated = #{updated,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.e3mall.pojo.TbItem" >
    update tb_item
    set title = #{title,jdbcType=VARCHAR},
      sell_point = #{sellPoint,jdbcType=VARCHAR},
      price = #{price,jdbcType=BIGINT},
      num = #{num,jdbcType=INTEGER},
      barcode = #{barcode,jdbcType=VARCHAR},
      image = #{image,jdbcType=VARCHAR},
      cid = #{cid,jdbcType=BIGINT},
      status = #{status,jdbcType=TINYINT},
      created = #{created,jdbcType=TIMESTAMP},
      updated = #{updated,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>
View Code

 

ItemService.class  接口

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 package cn.e3mall.service;
 2 
 3 import cn.e3mall.pojo.TbItem;
 4 
 5 /**
 6  * 商品管理Service
 7  */
 8 public interface ItemService {
 9     /**
10      * 根据商品id查询商品信息
11      *
12      * @param id
13      * @return
14      */
15     public TbItem getItemByid(long id);
16 }
View Code

 

ItemServiceImpl.class 实现类

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 package cn.e3mall.service.impl;
 2 import cn.e3mall.service.ItemService;
 3 import cn.e3mall.mapper.TbItemMapper;
 4 import cn.e3mall.pojo.TbItem;
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.stereotype.Service;
 7 
 8 /**
 9  * 商品管理Service
10  */
11 @Service
12 class ItemServiceImpl implements ItemService {
13 
14     @Autowired
15     private TbItemMapper itemMapper;
16 
17     /**
18      * 根据id查询商品
19      * @param id
20      * @return
21      */
22     @Override
23     public TbItem getItemByid(long id) {
24         TbItem item = itemMapper.selectByPrimaryKey(id);
25         return item;
26     }
27 }
View Code

 

ItemController.Class

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
 1 package cn.e3mall.controller;
 2 
 3 import cn.e3mall.service.ItemService;
 4 import cn.e3mall.pojo.TbItem;
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.stereotype.Controller;
 7 import org.springframework.web.bind.annotation.PathVariable;
 8 import org.springframework.web.bind.annotation.RequestMapping;
 9 import org.springframework.web.bind.annotation.ResponseBody;
10 
11 /**
12  * 商品管理Controller
13  */
14 @Controller
15 public class ItemController {
16     @Autowired
17     private ItemService itemService;
18 
19     @RequestMapping("/item/{itemId}")
20     @ResponseBody
21     public TbItem getItemById(@PathVariable Long itemId){
22         System.out.println(itemId);
23         TbItem item=itemService.getItemByid(itemId);
24         System.out.println(item.toString());
25         return item;
26     }
27 }
View Code

 

 

五、intellij maven工程运行

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

运行项目后,在控制台可以看到如下图所示。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 

 去浏览器输入地址后可以看到项目运行成功。

使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化