SSM 框架整合案例

Posted

tags:

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

项目源码地址 http://git.oschina.net/Lamb7/ssmdemo

1.使用maven构建项目,引入相关jar

<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/maven-v4_0_0.xsd">
    
    <!-- 当前pom的版本 -->
    <modelVersion>4.0.0</modelVersion>
    
    <!-- 主项目的标识 -->
    <groupId>ssm_Login</groupId>
    <artifactId>LoginDemo4</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <!-- Spring 、SpringMVC 的 相关 jar -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <!-- Servlet 的 jar -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>

        <!-- Mybatis 的 jar -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.8</version>
        </dependency>

        <!-- Mybatis 和 Spring 整合的 jar -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>


        <!-- mysql 的 驱动 jar -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.30</version>
        </dependency>

        <!-- alibaba 的数据源 的 jar -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.15</version>
        </dependency>

        <!-- 其它相关的jar -->
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.6</version>
        </dependency>

        <!-- log4j 的 jar 包 -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- fastjson的 jar -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.24</version>
        </dependency>



        <!-- 测试相关的 jar -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>

        <!-- 使用 responsebody 要使用的jar 包 ,或者直接引入 fastJson-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.1</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>LoginDemo4</finalName>
        <!-- 为了在 maven update 的时候不让 jdk 变成1.5 -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

 2.创建实体类 User.java

技术分享
 1 package model;
 2 
 3 import java.util.Date;
 4 import java.util.List;
 5 
 6 public class User {
 7 
 8     private Integer id;
 9 
10     private String username;
11 
12     private String password;
13 
14     private Float asset;
15 
16     private Short status;
17 
18     private Date createtime;
19 
20     private Date updatetime;
21 
22     public Integer getId() {
23         return id;
24     }
25 
26     public void setId(Integer id) {
27         this.id = id;
28     }
29 
30     public String getUsername() {
31         return username;
32     }
33 
34     public void setUsername(String username) {
35         this.username = username == null ? null : username.trim();
36     }
37 
38     public String getPassword() {
39         return password;
40     }
41 
42     public void setPassword(String password) {
43         this.password = password == null ? null : password.trim();
44     }
45 
46     public Float getAsset() {
47         return asset;
48     }
49 
50     public void setAsset(Float asset) {
51         this.asset = asset;
52     }
53 
54     public Short getStatus() {
55         return status;
56     }
57 
58     public void setStatus(Short status) {
59         this.status = status;
60     }
61 
62     public Date getCreatetime() {
63         return createtime;
64     }
65 
66     public void setCreatetime(Date createtime) {
67         this.createtime = createtime;
68     }
69 
70     public Date getUpdatetime() {
71         return updatetime;
72     }
73 
74     public void setUpdatetime(Date updatetime) {
75         this.updatetime = updatetime;
76     }
77 
78     public User() {
79         super();
80     }
81 
82     public User(String username, String password) {
83         super();
84         this.username = username;
85         this.password = password;
86     }
87 
88 }
View Code

 

以上是关于SSM 框架整合案例的主要内容,如果未能解决你的问题,请参考以下文章

Java之SSM框架整合-案例IDEA版(一篇文章精通系列)Spring+SpringMVC+MyBatis(整合源代码)

阶段3 3.SpringMVC·_07.SSM整合案例_03ssm整合之编写Spring框架

SSM 框架整合案例

JAVAEE框架技术之14SSM综合案例

JAVAEE框架技术之14SSM综合案例 产品管理CRUD

SSM用jq整合Ajax入门案例讲解