SSM简单搭建

Posted juncaoit

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSM简单搭建相关的知识,希望对你有一定的参考价值。

  参考了同事的文档,自己也写一篇文档。

一:新建项目

1.程序大纲

 

2.使用软件

  IDEA

 

3.新建Maven项目

  技术分享图片

 

4.定位

  技术分享图片

 

5.设置maven

  技术分享图片

 

6.项目保存路径

  技术分享图片

 

二:到目前为止的效果

1.大纲

  技术分享图片

 

2.配置tomcat

  技术分享图片

 

3.clean install

 

4.运行效果

  技术分享图片

 

5.web.xml

1 <!DOCTYPE web-app PUBLIC
2  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3  "http://java.sun.com/dtd/web-app_2_3.dtd" >
4 
5 <web-app>
6   <display-name>Archetype Created Web Application</display-name>
7 </web-app>

 

6.pom.xml

  这个pom感觉有点繁。不过现在是生成的,就先原本粘贴了。

 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>jun.it</groupId>
 8   <artifactId>ssm</artifactId>
 9   <version>1.0-SNAPSHOT</version>
10   <packaging>war</packaging>
11 
12   <name>ssm Maven Webapp</name>
13 
14   <url>http://www.example.com</url>
15 
16   <properties>
17     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18     <maven.compiler.source>1.7</maven.compiler.source>
19     <maven.compiler.target>1.7</maven.compiler.target>
20   </properties>
21 
22   <dependencies>
23     <dependency>
24       <groupId>junit</groupId>
25       <artifactId>junit</artifactId>
26       <version>4.11</version>
27       <scope>test</scope>
28     </dependency>
29   </dependencies>
30 
31   <build>
32     <finalName>ssm</finalName>
33     <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
34       <plugins>
35         <plugin>
36           <artifactId>maven-clean-plugin</artifactId>
37           <version>3.0.0</version>
38         </plugin>
39         <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
40         <plugin>
41           <artifactId>maven-resources-plugin</artifactId>
42           <version>3.0.2</version>
43         </plugin>
44         <plugin>
45           <artifactId>maven-compiler-plugin</artifactId>
46           <version>3.7.0</version>
47         </plugin>
48         <plugin>
49           <artifactId>maven-surefire-plugin</artifactId>
50           <version>2.20.1</version>
51         </plugin>
52         <plugin>
53           <artifactId>maven-war-plugin</artifactId>
54           <version>3.2.0</version>
55         </plugin>
56         <plugin>
57           <artifactId>maven-install-plugin</artifactId>
58           <version>2.5.2</version>
59         </plugin>
60         <plugin>
61           <artifactId>maven-deploy-plugin</artifactId>
62           <version>2.8.2</version>
63         </plugin>
64       </plugins>
65     </pluginManagement>
66   </build>
67 </project>

 

7.web.xml

1 <html>
2 <body>
3 <h2>Hello World!</h2>
4 </body>
5 </html>

 

三:引入新的包

1.需要的最少的包

  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>jun.it</groupId>
  8   <artifactId>ssm</artifactId>
  9   <version>1.0-SNAPSHOT</version>
 10   <packaging>war</packaging>
 11 
 12   <name>ssm Maven Webapp</name>
 13 
 14   <url>http://www.example.com</url>
 15 
 16   <properties>
 17     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 18     <maven.compiler.source>1.7</maven.compiler.source>
 19     <maven.compiler.target>1.7</maven.compiler.target>
 20     <!--自己新添加的版本-->
 21     <junit.version>4.11</junit.version>
 22     <mybatis.version>3.4.6</mybatis.version>
 23     <mysql.version>8.0.11</mysql.version>
 24     <spring.version>5.0.4.RELEASE</spring.version>
 25     <mybatis-spring.version>1.3.2</mybatis-spring.version>
 26     <commons-dbpc.version>1.4</commons-dbpc.version>
 27   </properties>
 28 
 29   <dependencies>
 30     <!--测试-->
 31     <dependency>
 32       <groupId>junit</groupId>
 33       <artifactId>junit</artifactId>
 34       <version>${junit.version}</version>
 35       <scope>test</scope>
 36     </dependency>
 37 
 38     <!-- dbcp数据源 -->
 39     <dependency>
 40       <groupId>commons-dbcp</groupId>
 41       <artifactId>commons-dbcp</artifactId>
 42       <version>${commons-dbpc.version}</version>
 43     </dependency>
 44 
 45     <!--mysql的连接包-->
 46     <!--JDBC Type 4 driver for MySQL-->
 47     <dependency>
 48       <groupId>mysql</groupId>
 49       <artifactId>mysql-connector-java</artifactId>
 50       <version>${mysql.version}</version>
 51     </dependency>
 52 
 53     <!-- Mybatis3.4.1 -->
 54     <dependency>
 55       <groupId>org.mybatis</groupId>
 56       <artifactId>mybatis</artifactId>
 57       <version>${mybatis.version}</version>
 58     </dependency>
 59 
 60     <!-- spring整合mybatis -->
 61     <!--An easy-to-use Spring bridge for MyBatis sql mapping framework.-->
 62     <dependency>
 63       <groupId>org.mybatis</groupId>
 64       <artifactId>mybatis-spring</artifactId>
 65       <version>${mybatis-spring.version}</version>
 66     </dependency>
 67 
 68     <!-- spring核心包 -->
 69     <!--spring-core-->
 70     <dependency>
 71       <groupId>org.springframework</groupId>
 72       <artifactId>spring-core</artifactId>
 73       <version>${spring.version}</version>
 74     </dependency>
 75 
 76     <!--Spring JDBC-->
 77     <dependency>
 78       <groupId>org.springframework</groupId>
 79       <artifactId>spring-jdbc</artifactId>
 80       <version>${spring.version}</version>
 81     </dependency>
 82 
 83     <!--Spring WebMVC-->
 84     <dependency>
 85       <groupId>org.springframework</groupId>
 86       <artifactId>spring-webmvc</artifactId>
 87       <version>${spring.version}</version>
 88     </dependency>
 89 
 90     <!--Spring Context-->
 91     <dependency>
 92       <groupId>org.springframework</groupId>
 93       <artifactId>spring-context</artifactId>
 94       <version>${spring.version}</version>
 95     </dependency>
 96   </dependencies>
 97 
 98   <build>
 99     <finalName>ssm</finalName>
100     <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
101       <plugins>
102         <plugin>
103           <artifactId>maven-clean-plugin</artifactId>
104           <version>3.0.0</version>
105         </plugin>
106         <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
107         <plugin>
108           <artifactId>maven-resources-plugin</artifactId>
109           <version>3.0.2</version>
110         </plugin>
111         <plugin>
112           <artifactId>maven-compiler-plugin</artifactId>
113           <version>3.7.0</version>
114         </plugin>
115         <plugin>
116           <artifactId>maven-surefire-plugin</artifactId>
117           <version>2.20.1</version>
118         </plugin>
119         <plugin>
120           <artifactId>maven-war-plugin</artifactId>
121           <version>3.2.0</version>
122         </plugin>
123         <plugin>
124           <artifactId>maven-install-plugin</artifactId>
125           <version>2.5.2</version>
126         </plugin>
127         <plugin>
128           <artifactId>maven-deploy-plugin</artifactId>
129           <version>2.8.2</version>
130         </plugin>
131       </plugins>
132     </pluginManagement>
133   </build>
134 </project>

 

2.剩下的自己选择使用

 1   <dependency>
 2     <groupId>org.springframework</groupId>
 3     <artifactId>spring-web</artifactId>
 4     <version>${spring.version}</version>
 5   </dependency>
 6   <dependency>
 7     <groupId>org.springframework</groupId>
 8     <artifactId>spring-oxm</artifactId>
 9     <version>${spring.version}</version>
10   </dependency>
11   <dependency>
12     <groupId>org.springframework</groupId>
13     <artifactId>spring-tx</artifactId>
14     <version>${spring.version}</version>
15   </dependency>
16   <dependency>
17     <groupId>org.springframework</groupId>
18     <artifactId>spring-aop</artifactId>
19     <version>${spring.version}</version>
20   </dependency>
21   <dependency>
22     <groupId>org.springframework</groupId>
23     <artifactId>spring-orm</artifactId>
24     <version>${spring.version}</version>
25   </dependency>
26   <dependency>
27     <groupId>org.springframework</groupId>
28     <artifactId>spring-beans</artifactId>
29     <version>${spring.version}</version>
30   </dependency>
31   <dependency>
32     <groupId>org.springframework</groupId>
33     <artifactId>spring-context-support</artifactId>
34     <version>${spring.version}</version>
35   </dependency>
36   <dependency>
37     <groupId>org.springframework</groupId>
38     <artifactId>spring-aspects</artifactId>
39     <version>${spring.version}</version>
40   </dependency>
41   <dependency>
42     <groupId>org.springframework</groupId>
43     <artifactId>spring-test</artifactId>
44     <version>${spring.version}</version>
45   </dependency>

 

四:开始创建MVC目录

1.

 

以上是关于SSM简单搭建的主要内容,如果未能解决你的问题,请参考以下文章

简单的SSM框架搭建教程

SSM项目搭建

ssm搭建简单web项目实现CURD

使用idea搭建一个简单的SSM框架:配置spring+mybatis

SSM框架简单搭建

SSM简单搭建