首页 > 其他 > 详细

SSM框架整合学习笔记

时间:2020-05-13 21:12:46      阅读:66      评论:0      收藏:0      [点我收藏+]

总体思路:Spring框架来整合另外两个框架。

  环境搭建

步骤1:创建一个ssm数据库,其中创建一个account表格,包含name,age,money三个字段。代码如下:

 

技术分享图片
1 CREATE DATABASE ssm;
2 USE ssm;
3 CREATE TABLE account(
4 id INT PRIMARY KEY AUTO_INCREMENT,
5 NAME VARCHAR(20),
6 money DOUBLE
7 );
View Code

 

步骤2:创建一个maven工程,选择webapp骨架

步骤3:在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 
  7   <groupId>org.example</groupId>
  8   <artifactId>SSM</artifactId>
  9   <version>1.0-SNAPSHOT</version>
 10   <packaging>war</packaging>
 11 
 12   <name>SSM Maven Webapp</name>
 13   <!-- FIXME change it to the project‘s website -->
 14   <url>http://www.example.com</url>
 15 
 16   <properties>
 17     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 18     <maven.compiler.source>1.8</maven.compiler.source>
 19     <maven.compiler.target>1.8</maven.compiler.target>
 20     <spring.version>5.0.2.RELEASE</spring.version>
 21     <slf4j.version>1.6.6</slf4j.version>
 22     <log4j.version>1.2.12</log4j.version>
 23     <mysql.version>5.1.6</mysql.version>
 24     <mybatis.version>3.4.5</mybatis.version>
 25   </properties>
 26 
 27   <dependencies>
 28     <!-- spring -->
 29     <dependency>
 30       <groupId>org.aspectj</groupId>
 31       <artifactId>aspectjweaver</artifactId>
 32       <version>1.6.8</version>
 33     </dependency>
 34     <dependency>
 35       <groupId>org.springframework</groupId>
 36       <artifactId>spring-aop</artifactId>
 37       <version>${spring.version}</version>
 38     </dependency>
 39     <dependency>
 40       <groupId>org.springframework</groupId>
 41       <artifactId>spring-context</artifactId>
 42       <version>${spring.version}</version>
 43     </dependency>
 44     <dependency>
 45       <groupId>org.springframework</groupId>
 46       <artifactId>spring-web</artifactId>
 47       <version>${spring.version}</version>
 48     </dependency>
 49     <dependency>
 50       <groupId>org.springframework</groupId>
 51       <artifactId>spring-webmvc</artifactId>
 52       <version>${spring.version}</version>
 53     </dependency>
 54     <dependency>
 55       <groupId>org.springframework</groupId>
 56       <artifactId>spring-test</artifactId>
 57       <version>${spring.version}</version>
 58     </dependency>
 59     <dependency>
 60       <groupId>org.springframework</groupId>
 61       <artifactId>spring-tx</artifactId>
 62       <version>${spring.version}</version>
 63     </dependency>
 64     <dependency>
 65       <groupId>org.springframework</groupId>
 66       <artifactId>spring-jdbc</artifactId>
 67       <version>${spring.version}</version>
 68     </dependency>
 69     <dependency>
 70       <groupId>junit</groupId>
 71       <artifactId>junit</artifactId>
 72       <version>4.12</version>
 73       <scope>compile</scope>
 74     </dependency>
 75     <dependency>
 76       <groupId>mysql</groupId>
 77       <artifactId>mysql-connector-java</artifactId>
 78       <version>${mysql.version}</version>
 79     </dependency>
 80     <dependency>
 81       <groupId>javax.servlet</groupId>
 82       <artifactId>servlet-api</artifactId>
 83       <version>2.5</version>
 84       <scope>provided</scope>
 85     </dependency>
 86     <dependency>
 87       <groupId>javax.servlet.jsp</groupId>
 88       <artifactId>jsp-api</artifactId>
 89       <version>2.0</version>
 90       <scope>provided</scope>
 91     </dependency>
 92     <dependency>
 93       <groupId>jstl</groupId>
 94       <artifactId>jstl</artifactId>
 95       <version>1.2</version>
 96     </dependency>
 97     <!-- log start -->
 98     <dependency>
 99       <groupId>log4j</groupId>
100       <artifactId>log4j</artifactId>
101       <version>${log4j.version}</version>
102     </dependency>
103     <dependency>
104       <groupId>org.slf4j</groupId>
105       <artifactId>slf4j-api</artifactId>
106       <version>${slf4j.version}</version>
107     </dependency>
108     <dependency>
109       <groupId>org.slf4j</groupId>
110       <artifactId>slf4j-log4j12</artifactId>
111       <version>${slf4j.version}</version>
112     </dependency>
113     <!-- log end -->
114     <dependency>
115       <groupId>org.mybatis</groupId>
116       <artifactId>mybatis</artifactId>
117       <version>${mybatis.version}</version>
118     </dependency>
119     <dependency>
120       <groupId>org.mybatis</groupId>
121       <artifactId>mybatis-spring</artifactId>
122       <version>1.3.0</version>
123     </dependency>
124     <dependency>
125       <groupId>c3p0</groupId>
126       <artifactId>c3p0</artifactId>
127       <version>0.9.1.2</version>
128       <type>jar</type>
129       <scope>compile</scope>
130     </dependency>
131   </dependencies>
132 
133   <build>
134     <finalName>SSM</finalName>
135     <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
136       <plugins>
137         <plugin>
138           <artifactId>maven-clean-plugin</artifactId>
139           <version>3.1.0</version>
140         </plugin>
141         <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
142         <plugin>
143           <artifactId>maven-resources-plugin</artifactId>
144           <version>3.0.2</version>
145         </plugin>
146         <plugin>
147           <artifactId>maven-compiler-plugin</artifactId>
148           <version>3.8.0</version>
149         </plugin>
150         <plugin>
151           <artifactId>maven-surefire-plugin</artifactId>
152           <version>2.22.1</version>
153         </plugin>
154         <plugin>
155           <artifactId>maven-war-plugin</artifactId>
156           <version>3.2.2</version>
157         </plugin>
158         <plugin>
159           <artifactId>maven-install-plugin</artifactId>
160           <version>2.5.2</version>
161         </plugin>
162         <plugin>
163           <artifactId>maven-deploy-plugin</artifactId>
164           <version>2.8.2</version>
165         </plugin>
166       </plugins>
167     </pluginManagement>
168   </build>
169 </project>
View Code

步骤4:补全main目录,在java目录下创建各个层的包与接口,类文件,结构如下:

注意:domain中的Account是一个与数据库account表格对应的JabaBean。

技术分享图片

 

SSM框架整合学习笔记

原文:https://www.cnblogs.com/augenstern/p/12884790.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!