服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - 使用IntelliJ IDEA搭建SSM框架的图文教程

使用IntelliJ IDEA搭建SSM框架的图文教程

2021-05-03 11:23Devilyang123 Java教程

本文通过图文并茂的形式给大家介绍了使用IntelliJ IDEA搭建SSM框架的教程,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

1.使用idea新建项目

使用IntelliJ IDEA搭建SSM框架的图文教程

2.选择创建maven工程

使用IntelliJ IDEA搭建SSM框架的图文教程

3.填写groupid和artifactid

使用IntelliJ IDEA搭建SSM框架的图文教程

4.填写项目名称,与上一步的artifactid一致即可,然后点finish

使用IntelliJ IDEA搭建SSM框架的图文教程

5.刚建好的目录只是一个maven的目录结构,如下

使用IntelliJ IDEA搭建SSM框架的图文教程

6.完善目录结构,添加webapp、web-inf目录,以及web.xml文件

使用IntelliJ IDEA搭建SSM框架的图文教程

7.修改idea的maven设置,maven默认的本地仓库会保存在c盘,为了方便以后使用,尽量修改本地仓库的位置,因为这是框架整合,所以具体的修改方式在这里不多做说明。快捷键ctrl+alt+s,在搜索框中搜索maven,如下


使用IntelliJ IDEA搭建SSM框架的图文教程

9.修改maven的核心配置文件pom.xml,添加框架所需要的依赖

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?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.xiao</groupid>
 <artifactid>ssm</artifactid>
 <version>1.0-snapshot</version>
 <packaging>war</packaging>
 <!-- 提取版本属性 -->
 <properties>
  <spring.version>4.2.4.release</spring.version>
  <mybatis.version>3.2.8</mybatis.version>
  <mybatis.spring.version>1.2.2</mybatis.spring.version>
  <slf4j.version>1.6.4</slf4j.version>
  <log4j.version>1.2.17</log4j.version>
  <jackson.version>2.4.2</jackson.version>
  <druid.version>1.0.9</druid.version>
  <mysql.version>5.1.32</mysql.version>
  <jstl.version>1.2</jstl.version>
  <servlet-api.version>2.5</servlet-api.version>
  <jsp-api.version>2.0</jsp-api.version>
  <commons-io.version>1.3.2</commons-io.version>
  <commons-fileupload.version>1.3.1</commons-fileupload.version>
 </properties>
 <!-- 版本锁定 -->
 <dependencymanagement>
  <dependencies>
   <!-- spring -->
   <dependency>
    <groupid>org.springframework</groupid>
    <artifactid>spring-context</artifactid>
    <version>${spring.version}</version>
   </dependency>
   <dependency>
    <groupid>org.springframework</groupid>
    <artifactid>spring-beans</artifactid>
    <version>${spring.version}</version>
   </dependency>
   <dependency>
    <groupid>org.springframework</groupid>
    <artifactid>spring-webmvc</artifactid>
    <version>${spring.version}</version>
   </dependency>
   <dependency>
    <groupid>org.springframework</groupid>
    <artifactid>spring-jdbc</artifactid>
    <version>${spring.version}</version>
   </dependency>
   <dependency>
    <groupid>org.springframework</groupid>
    <artifactid>spring-aspects</artifactid>
    <version>${spring.version}</version>
   </dependency>
   <dependency>
    <groupid>org.springframework</groupid>
    <artifactid>spring-jms</artifactid>
    <version>${spring.version}</version>
   </dependency>
   <dependency>
    <groupid>org.springframework</groupid>
    <artifactid>spring-context-support</artifactid>
    <version>${spring.version}</version>
   </dependency>
   <!-- mybatis -->
   <dependency>
    <groupid>org.mybatis</groupid>
    <artifactid>mybatis</artifactid>
    <version>${mybatis.version}</version>
   </dependency>
   <dependency>
    <groupid>org.mybatis</groupid>
    <artifactid>mybatis-spring</artifactid>
    <version>${mybatis.spring.version}</version>
   </dependency>
   <!-- 日志处理 -->
   <dependency>
    <groupid>org.slf4j</groupid>
    <artifactid>slf4j-log4j12</artifactid>
    <version>${slf4j.version}</version>
   </dependency>
   <dependency>
    <groupid>log4j</groupid>
    <artifactid>log4j</artifactid>
    <version>${log4j.version}</version>
   </dependency>
   <!-- jackson json处理工具包 -->
   <dependency>
    <groupid>com.fasterxml.jackson.core</groupid>
    <artifactid>jackson-databind</artifactid>
    <version>${jackson.version}</version>
   </dependency>
   <!-- 连接池 -->
   <dependency>
    <groupid>com.alibaba</groupid>
    <artifactid>druid</artifactid>
    <version>${druid.version}</version>
   </dependency>
   <!-- mysql -->
   <dependency>
    <groupid>mysql</groupid>
    <artifactid>mysql-connector-java</artifactid>
    <version>${mysql.version}</version>
   </dependency>
   <!-- io包 -->
   <dependency>
    <groupid>org.apache.commons</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>
   <!-- jsp相关 -->
   <dependency>
    <groupid>jstl</groupid>
    <artifactid>jstl</artifactid>
    <version>${jstl.version}</version>
   </dependency>
   <dependency>
    <groupid>javax.servlet</groupid>
    <artifactid>servlet-api</artifactid>
    <version>${servlet-api.version}</version>
    <scope>provided</scope>
   </dependency>
   <dependency>
    <groupid>javax.servlet</groupid>
    <artifactid>jsp-api</artifactid>
    <version>${jsp-api.version}</version>
    <scope>provided</scope>
   </dependency>
  </dependencies>
 </dependencymanagement>
 <!-- 添加依赖 -->
 <dependencies>
  <!-- spring -->
  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-context</artifactid>
  </dependency>
  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-beans</artifactid>
  </dependency>
  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-webmvc</artifactid>
  </dependency>
  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-jdbc</artifactid>
  </dependency>
  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-aspects</artifactid>
  </dependency>
  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-jms</artifactid>
  </dependency>
  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-context-support</artifactid>
  </dependency>
  <!-- mybatis -->
  <dependency>
   <groupid>org.mybatis</groupid>
   <artifactid>mybatis</artifactid>
  </dependency>
  <dependency>
   <groupid>org.mybatis</groupid>
   <artifactid>mybatis-spring</artifactid>
  </dependency>
  <!-- 日志处理 -->
  <dependency>
   <groupid>org.slf4j</groupid>
   <artifactid>slf4j-log4j12</artifactid>
  </dependency>
  <!-- jackson json处理工具包 -->
  <dependency>
   <groupid>com.fasterxml.jackson.core</groupid>
   <artifactid>jackson-databind</artifactid>
  </dependency>
  <!-- 连接池 -->
  <dependency>
   <groupid>com.alibaba</groupid>
   <artifactid>druid</artifactid>
  </dependency>
  <!-- mysql -->
  <dependency>
   <groupid>mysql</groupid>
   <artifactid>mysql-connector-java</artifactid>
  </dependency>
  <!-- io包 -->
  <dependency>
   <groupid>org.apache.commons</groupid>
   <artifactid>commons-io</artifactid>
  </dependency>
  <!-- 文件上传组件 -->
  <dependency>
   <groupid>commons-fileupload</groupid>
   <artifactid>commons-fileupload</artifactid>
  </dependency>
  <!-- jsp相关 -->
  <dependency>
   <groupid>jstl</groupid>
   <artifactid>jstl</artifactid>
  </dependency>
  <dependency>
   <groupid>javax.servlet</groupid>
   <artifactid>servlet-api</artifactid>
   <scope>provided</scope>
  </dependency>
  <dependency>
   <groupid>javax.servlet</groupid>
   <artifactid>jsp-api</artifactid>
   <scope>provided</scope>
  </dependency>
 </dependencies>
 <build>
  <!-- java编译插件 -->
  <plugins>
   <plugin>
    <groupid>org.apache.maven.plugins</groupid>
    <artifactid>maven-compiler-plugin</artifactid>
    <version>3.2</version>
    <configuration>
     <source>1.8</source>
     <target>1.8</target>
     <encoding>utf-8</encoding>
    </configuration>
   </plugin>
  </plugins>
  <!--配置资源文件映射 -->
  <resources>
   <resource>
    <directory>src/main/java</directory>
    <includes>
     <include>**/*.xml</include>
    </includes>
    <filtering>false</filtering>
   </resource>
   <resource>
    <directory>src/main/resources</directory>
    <includes>
     <include>**/*.properties</include>
     <include>**/*.xml</include>
    </includes>
    <filtering>false</filtering>
   </resource>
  </resources>
 </build>
</project>

10.在resources目录下添加配置文件

文件目录如下

使用IntelliJ IDEA搭建SSM框架的图文教程

a)连接数据库配置信息文件-db.properties

?
1
2
3
4
druid.driver=com.mysql.jdbc.driver
druid.url=jdbc:mysql://localhost:3306/all_db?characterencoding=utf-8
druid.username=root
druid.password=root

 b)mybatis核心配置文件-sqlmapconfig.xml

?
1
2
3
4
5
6
7
8
9
10
<?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>
 <!-- 给实体类起别名 -->
 <typealiases >
  <package name="com.xiao.pojo"/>
 </typealiases>
 </configuration>

c)spring核心配置文件,整合mybatis,applicationcontext.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx"
  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/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
 <!-- 加载数据库连接信息配置文件 -->
 <context:property-placeholder location="classpath:db.properties" />
 <!--druid连接池 -->
 <bean id="datasource" class="com.alibaba.druid.pool.druiddatasource">
  <property name="driverclassname" value="${druid.driver}" />
  <property name="url"   value="${druid.url}" />
  <property name="username"   value="${druid.username}" />
  <property name="password"   value="${druid.password}" />
 </bean>
 <!-- 配置mybatis工厂 -->
 <bean id="sqlsessionfactory" class="org.mybatis.spring.sqlsessionfactorybean">
  <property name="datasource" ref="datasource" />
  <property name="configlocation" value="classpath:sqlmapconfig.xml" />
 </bean>
 <!-- mapper动态代理开发 扫包 给定包下的接口文件名和映射文件名必须相同 创建接口的实现类-->
 <bean class="org.mybatis.spring.mapper.mapperscannerconfigurer">
  <property name="basepackage" value="com.xiao.mapper" />
 </bean>
 <!-- 开启事物 -->
 <bean id="transactionmanager" class="org.springframework.jdbc.datasource.datasourcetransactionmanager">
  <property name="datasource" ref="datasource" />
 </bean>
 <!-- 事物注解驱动-->
 <tx:annotation-driven />
</beans>

 d)springmvc配置文件-springmvc.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
  xmlns="http://www.springframework.org/schema/beans"
  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/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
 <!-- 配置扫描注解 @controller @service -->
 <context:component-scan base-package="com.xiao" />
 <!-- springmvc使用<mvc:annotation-driven>自动加载requestmappinghandlermapping和requestmappinghandleradapter -->
 <mvc:annotation-driven />
 <!-- 配置静态资源映射 -->
 <!--
 <mvc:resources location="/js/" mapping="/js/**"/>
 <mvc:resources location="/css/" mapping="/css/**"/>
 <mvc:resources location="/imgs/" mapping="/imgs/**"/>
 <mvc:resources location="/font/" mapping="/font/**"/>
 -->
 <!-- 配置视图解析器-->
 <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">
  <!-- 配置逻辑视图的前缀 -->
  <property name="prefix" value="/web-inf/jsp/" />
  <!-- 配置逻辑视图的后缀 -->
  <property name="suffix" value=".jsp" />
 </bean>
</beans>

11.配置web.xml文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
   xsi:schemalocation="http://java.sun.com/xml/ns/javaee
   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5">
 <display-name>ssm</display-name>
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
 <!-- spring监听器 -->
 <listener>
  <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>
 </listener>
 <!-- 指定spring核心配置文件 -->
 <context-param>
  <param-name>contextconfiglocation</param-name>
  <param-value>classpath:applicationcontext.xml</param-value>
 </context-param>
 <!-- 处理post提交乱码问题 -->
 <filter>
  <filter-name>encoding</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>encoding</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- 配置前端控制器 -->
 <servlet>
  <servlet-name>springmvc</servlet-name>
  <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>
  <!-- 指定配置文件位置和名称 如果不设置,默认找/web-inf/<servlet-name>-servlet.xml -->
  <init-param>
   <param-name>contextconfiglocation</param-name>
   <param-value>classpath:springmvc.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>springmvc</servlet-name>
  <url-pattern>/</url-pattern>
 </servlet-mapping>
</web-app>

12.完善目录结构,书写实体类、web层、service层、dao层以及测试页面,目录结构如下

使用IntelliJ IDEA搭建SSM框架的图文教程

13.配置tomcat

使用IntelliJ IDEA搭建SSM框架的图文教程

使用IntelliJ IDEA搭建SSM框架的图文教程

使用IntelliJ IDEA搭建SSM框架的图文教程

使用IntelliJ IDEA搭建SSM框架的图文教程

使用IntelliJ IDEA搭建SSM框架的图文教程

使用IntelliJ IDEA搭建SSM框架的图文教程

14.启动tomcat,访问地址: http://localhost:8080/getall   进行测试,结果如下

使用IntelliJ IDEA搭建SSM框架的图文教程

出现以上结果,表示ssm框架搭建成功!

数据库数据如下

使用IntelliJ IDEA搭建SSM框架的图文教程

在jsp页面用el表达式取值

总结

以上所述是小编给大家介绍的使用intellij idea搭建ssm框架的图文教程,希望对大家有所帮助如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:https://blog.csdn.net/u012430402/article/details/80385878

延伸 · 阅读

精彩推荐