码迷,mamicode.com
首页 > 其他好文 > 详细

idea搭建ssm框架

时间:2018-08-17 23:29:04      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:command   modules   alibaba   eth   like   ISE   project   jsp   uil   

1、基本概念

 

1.1、Spring 

        Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Development and Design中阐述的部分理念和原型衍生而来。它是为了解决企业应用开发的复杂性而创建的。Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情。然而,Spring的用途不仅限于服务器端的开发。从简单性、可测试性和松耦合的角度而言,任何Java应用都可以从Spring中受益。 简单来说,Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架。

 

1.2、SpringMVC     

        Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面。Spring MVC 分离了控制器、模型对象、分派器以及处理程序对象的角色,这种分离让它们更容易进行定制。

 

1.3、MyBatis

       MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis 。MyBatis是一个基于Java的持久层框架。iBATIS提供的持久层框架包括SQL Maps和Data Access Objects(DAO)MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索。MyBatis 使用简单的 XML或注解用于配置和原始映射,将接口和 Java 的POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。

 

 

2、开发环境搭建以及创建Maven Web项目

1.jdk1.8   

2.idea

3.maven    tomcat

技术分享图片

 

settings.xml

技术分享图片
  1 <?xml version="1.0" encoding="UTF-8"?>
  2 
  3 <!--
  4 Licensed to the Apache Software Foundation (ASF) under one
  5 or more contributor license agreements.  See the NOTICE file
  6 distributed with this work for additional information
  7 regarding copyright ownership.  The ASF licenses this file
  8 to you under the Apache License, Version 2.0 (the
  9 "License"); you may not use this file except in compliance
 10 with the License.  You may obtain a copy of the License at
 11 
 12     http://www.apache.org/licenses/LICENSE-2.0
 13 
 14 Unless required by applicable law or agreed to in writing,
 15 software distributed under the License is distributed on an
 16 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17 KIND, either express or implied.  See the License for the
 18 specific language governing permissions and limitations
 19 under the License.
 20 -->
 21 
 22 <!--
 23  | This is the configuration file for Maven. It can be specified at two levels:
 24  |
 25  |  1. User Level. This settings.xml file provides configuration for a single user,
 26  |                 and is normally provided in ${user.home}/.m2/settings.xml.
 27  |
 28  |                 NOTE: This location can be overridden with the CLI option:
 29  |
 30  |                 -s /path/to/user/settings.xml
 31  |
 32  |  2. Global Level. This settings.xml file provides configuration for all Maven
 33  |                 users on a machine (assuming they‘re all using the same Maven
 34  |                 installation). It‘s normally provided in
 35  |                 ${maven.conf}/settings.xml.
 36  |
 37  |                 NOTE: This location can be overridden with the CLI option:
 38  |
 39  |                 -gs /path/to/global/settings.xml
 40  |
 41  | The sections in this sample file are intended to give you a running start at
 42  | getting the most out of your Maven installation. Where appropriate, the default
 43  | values (values used when the setting is not specified) are provided.
 44  |
 45  |-->
 46 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
 47           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 48           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 49   <!-- localRepository
 50    | The path to the local repository maven will use to store artifacts.
 51    |
 52    | Default: ${user.home}/.m2/repository
 53   <localRepository>/path/to/local/repo</localRepository>
 54   -->
 55   <localRepository>D:\Develop\MvnRepo</localRepository>
 56 
 57   <!-- interactiveMode
 58    | This will determine whether maven prompts you when it needs input. If set to false,
 59    | maven will use a sensible default value, perhaps based on some other setting, for
 60    | the parameter in question.
 61    |
 62    | Default: true
 63   <interactiveMode>true</interactiveMode>
 64   -->
 65 
 66   <!-- offline
 67    | Determines whether maven should attempt to connect to the network when executing a build.
 68    | This will have an effect on artifact downloads, artifact deployment, and others.
 69    |
 70    | Default: false
 71   <offline>false</offline>
 72   -->
 73 
 74   <!-- pluginGroups
 75    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
 76    | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
 77    | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
 78    |-->
 79   <pluginGroups>
 80     <!-- pluginGroup
 81      | Specifies a further group identifier to use for plugin lookup.
 82     <pluginGroup>com.your.plugins</pluginGroup>
 83     -->
 84   </pluginGroups>
 85 
 86   <!-- proxies
 87    | This is a list of proxies which can be used on this machine to connect to the network.
 88    | Unless otherwise specified (by system property or command-line switch), the first proxy
 89    | specification in this list marked as active will be used.
 90    |-->
 91   <proxies>
 92     <!-- proxy
 93      | Specification for one proxy, to be used in connecting to the network.
 94      |
 95     <proxy>
 96       <id>optional</id>
 97       <active>true</active>
 98       <protocol>http</protocol>
 99       <username>proxyuser</username>
100       <password>proxypass</password>
101       <host>proxy.host.net</host>
102       <port>80</port>
103       <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
104     </proxy>
105     -->
106   </proxies>
107 
108   <!-- servers
109    | This is a list of authentication profiles, keyed by the server-id used within the system.
110    | Authentication profiles can be used whenever maven must make a connection to a remote server.
111    |-->
112   <servers>
113     <!-- server
114      | Specifies the authentication information to use when connecting to a particular server, identified by
115      | a unique name within the system (referred to by the ‘id‘ attribute below).
116      |
117      | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
118      |       used together.
119      |
120     <server>
121       <id>deploymentRepo</id>
122       <username>repouser</username>
123       <password>repopwd</password>
124     </server>
125     -->
126 
127     <!-- Another sample, using keys to authenticate.
128     <server>
129       <id>siteServer</id>
130       <privateKey>/path/to/private/key</privateKey>
131       <passphrase>optional; leave empty if not used.</passphrase>
132     </server>
133     -->
134   </servers>
135 
136   <!-- mirrors
137    | This is a list of mirrors to be used in downloading artifacts from remote repositories.
138    |
139    | It works like this: a POM may declare a repository to use in resolving certain artifacts.
140    | However, this repository may have problems with heavy traffic at times, so people have mirrored
141    | it to several places.
142    |
143    | That repository definition will have a unique id, so we can create a mirror reference for that
144    | repository, to be used as an alternate download site. The mirror site will be the preferred
145    | server for that repository.
146    |-->
147   <mirrors>
148     <mirror>  
149       <id>nexus-aliyun</id>
150       <mirrorOf>central</mirrorOf>
151       <name>Nexus aliyun</name>
152       <url>http://maven.aliyun.com/nexus/content/repositories/central</url>        
153     </mirror>  
154     <!-- mirror
155      | Specifies a repository mirror site to use instead of a given repository. The repository that
156      | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
157      | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
158      |
159     <mirror>
160       <id>mirrorId</id>
161       <mirrorOf>repositoryId</mirrorOf>
162       <name>Human Readable Name for this Mirror.</name>
163       <url>http://my.repository.com/repo/path</url>
164     </mirror>
165      -->
166   </mirrors>
167 
168   <!-- profiles
169    | This is a list of profiles which can be activated in a variety of ways, and which can modify
170    | the build process. Profiles provided in the settings.xml are intended to provide local machine-
171    | specific paths and repository locations which allow the build to work in the local environment.
172    |
173    | For example, if you have an integration testing plugin - like cactus - that needs to know where
174    | your Tomcat instance is installed, you can provide a variable here such that the variable is
175    | dereferenced during the build process to configure the cactus plugin.
176    |
177    | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
178    | section of this document (settings.xml) - will be discussed later. Another way essentially
179    | relies on the detection of a system property, either matching a particular value for the property,
180    | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
181    | value of ‘1.4‘ might activate a profile when the build is executed on a JDK version of ‘1.4.2_07‘.
182    | Finally, the list of active profiles can be specified directly from the command line.
183    |
184    | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
185    |       repositories, plugin repositories, and free-form properties to be used as configuration
186    |       variables for plugins in the POM.
187    |
188    |-->
189   <profiles>
190     <!-- profile
191      | Specifies a set of introductions to the build process, to be activated using one or more of the
192      | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
193      | or the command line, profiles have to have an ID that is unique.
194      |
195      | An encouraged best practice for profile identification is to use a consistent naming convention
196      | for profiles, such as ‘env-dev‘, ‘env-test‘, ‘env-production‘, ‘user-jdcasey‘, ‘user-brett‘, etc.
197      | This will make it more intuitive to understand what the set of introduced profiles is attempting
198      | to accomplish, particularly when you only have a list of profile id‘s for debug.
199      |
200      | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
201     <profile>
202       <id>jdk-1.4</id>
203 
204       <activation>
205         <jdk>1.4</jdk>
206       </activation>
207 
208       <repositories>
209         <repository>
210           <id>jdk14</id>
211           <name>Repository for JDK 1.4 builds</name>
212           <url>http://www.myhost.com/maven/jdk14</url>
213           <layout>default</layout>
214           <snapshotPolicy>always</snapshotPolicy>
215         </repository>
216       </repositories>
217     </profile>
218     -->
219 
220     <!--
221      | Here is another profile, activated by the system property ‘target-env‘ with a value of ‘dev‘,
222      | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
223      | might hypothetically look like:
224      |
225      | ...
226      | <plugin>
227      |   <groupId>org.myco.myplugins</groupId>
228      |   <artifactId>myplugin</artifactId>
229      |
230      |   <configuration>
231      |     <tomcatLocation>${tomcatPath}</tomcatLocation>
232      |   </configuration>
233      | </plugin>
234      | ...
235      |
236      | NOTE: If you just wanted to inject this configuration whenever someone set ‘target-env‘ to
237      |       anything, you could just leave off the <value/> inside the activation-property.
238      |
239     <profile>
240       <id>env-dev</id>
241 
242       <activation>
243         <property>
244           <name>target-env</name>
245           <value>dev</value>
246         </property>
247       </activation>
248 
249       <properties>
250         <tomcatPath>/path/to/tomcat/instance</tomcatPath>
251       </properties>
252     </profile>
253     -->
254   </profiles>
255 
256   <!-- activeProfiles
257    | List of profiles that are active for all builds.
258    |
259   <activeProfiles>
260     <activeProfile>alwaysActiveProfile</activeProfile>
261     <activeProfile>anotherAlwaysActiveProfile</activeProfile>
262   </activeProfiles>
263   -->
264 </settings>
settings.xml

 

3.开始建立maven工程

技术分享图片

技术分享图片

技术分享图片

 

 

 技术分享图片

配置正确的话就会出现    刚开始配maven工程可能会久一点

技术分享图片

 

  3.1 在pom.xml中引入jar包

技术分享图片

 

技术分享图片

 

 

 之后的内容修改一下就好了,我把pom.xml文件放上

技术分享图片
  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   <groupId>com</groupId>
  7   <artifactId>blgg</artifactId>
  8   <version>1.0-SNAPSHOT</version>
  9   <packaging>war</packaging>
 10   <name>tables</name>
 11 
 12 
 13   <properties>
 14     <spring.version>4.1.4.RELEASE</spring.version>
 15     <mybatis.version>3.2.8</mybatis.version>
 16     <slf4j.version>1.7.7</slf4j.version>
 17     <log4j.version>1.2.17</log4j.version>
 18     <quartz.version>2.2.2</quartz.version>
 19     <activiti.version>5.15.1</activiti.version>
 20   </properties>
 21 
 22 
 23   <dependencies>
 24 
 25     <dependency>
 26       <groupId>org.springframework</groupId>
 27       <artifactId>spring-core</artifactId>
 28       <version>${spring.version}</version>
 29     </dependency>
 30     <dependency>
 31       <groupId>org.springframework</groupId>
 32       <artifactId>spring-context</artifactId>
 33       <version>${spring.version}</version>
 34     </dependency>
 35     <!-- 添加spring-tx包 -->
 36     <dependency>
 37       <groupId>org.springframework</groupId>
 38       <artifactId>spring-tx</artifactId>
 39       <version>${spring.version}</version>
 40     </dependency>
 41     <!-- 添加spring-jdbc包 -->
 42     <dependency>
 43       <groupId>org.springframework</groupId>
 44       <artifactId>spring-jdbc</artifactId>
 45       <version>${spring.version}</version>
 46     </dependency>
 47     <!-- 为了方便进行单元测试,添加spring-test包 -->
 48     <dependency>
 49       <groupId>org.springframework</groupId>
 50       <artifactId>spring-test</artifactId>
 51       <version>${spring.version}</version>
 52     </dependency>
 53     <!--添加spring-web包 -->
 54     <dependency>
 55       <groupId>org.springframework</groupId>
 56       <artifactId>spring-web</artifactId>
 57       <version>${spring.version}</version>
 58     </dependency>
 59     <dependency>
 60       <groupId>org.springframework</groupId>
 61       <artifactId>spring-webmvc</artifactId>
 62       <version>${spring.version}</version>
 63     </dependency>
 64     <dependency>
 65       <groupId>org.springframework</groupId>
 66       <artifactId>spring-aop</artifactId>
 67       <version>${spring.version}</version>
 68     </dependency>
 69     <dependency>
 70       <groupId>org.springframework</groupId>
 71       <artifactId>spring-context-support</artifactId>
 72       <version>${spring.version}</version>
 73     </dependency>
 74     <!--添加aspectjweaver包 -->
 75     <dependency>
 76       <groupId>org.aspectj</groupId>
 77       <artifactId>aspectjweaver</artifactId>
 78       <version>1.8.5</version>
 79     </dependency>
 80     <!-- 添加mybatis的核心包 -->
 81     <dependency>
 82       <groupId>org.mybatis</groupId>
 83       <artifactId>mybatis</artifactId>
 84       <version>${mybatis.version}</version>
 85     </dependency>
 86     <!-- 添加mybatis与Spring整合的核心包 -->
 87     <dependency>
 88       <groupId>org.mybatis</groupId>
 89       <artifactId>mybatis-spring</artifactId>
 90       <version>1.2.2</version>
 91     </dependency>
 92     <!-- 添加servlet3.0核心包 -->
 93     <dependency>
 94       <groupId>javax.servlet</groupId>
 95       <artifactId>javax.servlet-api</artifactId>
 96       <version>3.0.1</version>
 97     </dependency>
 98     <dependency>
 99       <groupId>javax.servlet.jsp</groupId>
100       <artifactId>javax.servlet.jsp-api</artifactId>
101       <version>2.3.2-b01</version>
102     </dependency>
103     <!-- jstl -->
104     <dependency>
105       <groupId>javax.servlet</groupId>
106       <artifactId>jstl</artifactId>
107       <version>1.2</version>
108     </dependency>
109     <!-- 添加mysql驱动包 -->
110     <dependency>
111       <groupId>mysql</groupId>
112       <artifactId>mysql-connector-java</artifactId>
113       <version>5.1.34</version>
114     </dependency>
115     <!-- 添加druid连接池包 -->
116     <dependency>
117       <groupId>com.alibaba</groupId>
118       <artifactId>druid</artifactId>
119       <version>1.0.12</version>
120     </dependency>
121     <!-- 日志文件管理包 -->
122     <!-- log start -->
123     <dependency>
124       <groupId>log4j</groupId>
125       <artifactId>log4j</artifactId>
126       <version>${log4j.version}</version>
127     </dependency>
128 
129 
130     <!-- 格式化对象,方便输出日志 -->
131     <dependency>
132       <groupId>com.alibaba</groupId>
133       <artifactId>fastjson</artifactId>
134       <version>1.1.41</version>
135     </dependency>
136 
137 
138     <dependency>
139       <groupId>org.slf4j</groupId>
140       <artifactId>slf4j-api</artifactId>
141       <version>${slf4j.version}</version>
142     </dependency>
143 
144     <dependency>
145       <groupId>org.slf4j</groupId>
146       <artifactId>slf4j-log4j12</artifactId>
147       <version>${slf4j.version}</version>
148     </dependency>
149     <!-- log end -->
150     <!--apache shiro  -->
151     <dependency>
152       <groupId>org.apache.shiro</groupId>
153       <artifactId>shiro-core</artifactId>
154       <version>1.2.2</version>
155     </dependency>
156     <dependency>
157       <groupId>org.apache.shiro</groupId>
158       <artifactId>shiro-web</artifactId>
159       <version>1.2.2</version>
160     </dependency>
161     <dependency>
162       <groupId>org.apache.shiro</groupId>
163       <artifactId>shiro-ehcache</artifactId>
164       <version>1.2.2</version>
165     </dependency>
166     <dependency>
167       <groupId>org.apache.shiro</groupId>
168       <artifactId>shiro-spring</artifactId>
169       <version>1.2.2</version>
170     </dependency>
171     <dependency>
172       <groupId>org.apache.shiro</groupId>
173       <artifactId>shiro-quartz</artifactId>
174       <version>1.2.2</version>
175     </dependency>
176     <!--apache shiro  end-->
177     <!-- 映入JSON -->
178     <dependency>
179       <groupId>org.codehaus.jackson</groupId>
180       <artifactId>jackson-mapper-asl</artifactId>
181       <version>1.9.13</version>
182     </dependency>
183     <!-- 上传组件包 -->
184     <dependency>
185       <groupId>commons-fileupload</groupId>
186       <artifactId>commons-fileupload</artifactId>
187       <version>1.3.1</version>
188     </dependency>
189     <dependency>
190       <groupId>commons-io</groupId>
191       <artifactId>commons-io</artifactId>
192       <version>2.4</version>
193     </dependency>
194     <dependency>
195       <groupId>commons-codec</groupId>
196       <artifactId>commons-codec</artifactId>
197       <version>1.9</version>
198     </dependency>
199     <dependency>
200       <groupId>org.quartz-scheduler</groupId>
201       <artifactId>quartz</artifactId>
202       <version>${quartz.version}</version>
203     </dependency>
204     <dependency>
205       <groupId>org.apache.velocity</groupId>
206       <artifactId>velocity</artifactId>
207       <version>1.7</version>
208     </dependency>
209     <dependency>
210       <groupId>org.apache.velocity</groupId>
211       <artifactId>velocity-tools</artifactId>
212       <version>2.0</version>
213     </dependency>
214 
215     <dependency>
216       <groupId>org.mybatis.generator</groupId>
217       <artifactId>mybatis-generator-core</artifactId>
218       <version>1.3.2</version>
219       <scope>test</scope>
220     </dependency>
221     <!--activity工作流依赖-->
222     <dependency>
223       <groupId>org.activiti</groupId>
224       <artifactId>activiti-engine</artifactId>
225       <version>${activiti.version}</version>
226     </dependency>
227     <!-- activiti 与 Spring 集成 -->
228     <dependency>
229       <groupId>org.activiti</groupId>
230       <artifactId>activiti-spring</artifactId>
231       <version>${activiti.version}</version>
232     </dependency>
233   </dependencies>
234 
235 
236   <build>
237     <finalName>blgg</finalName>
238 
239     <resources>
240       <resource>
241         <directory>src/main/java</directory>
242         <includes>
243           <include>**/*.xml</include>
244         </includes>
245       </resource>
246     </resources>
247 
248     <plugins>
249       <plugin>
250         <groupId>org.mybatis.generator</groupId>
251         <artifactId>mybatis-generator-maven-plugin</artifactId>
252         <version>1.3.2</version>
253         <configuration>
254           <verbose>true</verbose>
255           <overwrite>true</overwrite>
256         </configuration>
257       </plugin>
258       <plugin>
259         <groupId>org.apache.maven.plugins</groupId>
260         <artifactId>maven-compiler-plugin</artifactId>
261         <configuration>
262           <source>1.8</source>
263           <target>1.8</target>
264         </configuration>
265       </plugin>
266     </plugins>
267   </build>
268 
269 </project>
pom.xml

 

技术分享图片

 

 成功导入jar就是这样,如果没有就点击idea右下角右边的按钮Enable import

 

3.2 目录结构配置

在src-main目录创建一个java和resource

技术分享图片

 

并且在左上角File-Project Structure-Modules-Source

技术分享图片

 

 

 

之后apply-ok一下就好了

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

idea搭建ssm框架

标签:command   modules   alibaba   eth   like   ISE   project   jsp   uil   

原文地址:https://www.cnblogs.com/xiaobo520/p/9495507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!