使用IDEA maven搭建SSM框架

0 在pom.xml配置版本
<properties>
    <jdk.version>1.7</jdk.version>
    <jdk.encoding>UTF-8</jdk.encoding>
    <spring.version>4.3.0.RELEASE</spring.version>
    <mybatis.version>3.3.0</mybatis.version>
    <mybatis.spring.version>1.2.2</mybatis.spring.version>
    <mysql.driver.version>5.1.38</mysql.driver.version>
    <dbcp.version>1.4</dbcp.version>
    <servlet.version>3.1.0</servlet.version>
    <junit.version>4.12</junit.version>
    <fastjson.version>1.2.17</fastjson.version>
</properties>
0     设置JDK版本及编码
<!--设置JDK版本与编码-->
< plugin >
    < groupId >org.apache.maven.plugins </ groupId >
    < artifactId >maven-compiler-plugin </ artifactId >
    < version >3.3 </ version >
    < configuration >
        < source >${jdk.version} </ source >
        < target >${jdk.version} </ target >
        < encoding >${jdk.encoding} </ encoding >
    </ configuration >
</ plugin >
1在pom.xml中引入包的坐标
1.1Spring包
<!--Spring核心-->
< dependency >
    < groupId >org.springframework </ groupId >
    < artifactId >spring-context </ artifactId >
    < version >${spring.version} </ version >
</dependency>
1.2 Mybatis的包
<!--Mybatis核心-->
< dependency >
    < groupId >org.mybatis </ groupId >
    < artifactId >mybatis </ artifactId >
    < version >${mybatis.version} </ version >
</dependency>
1.3 Spring与Mybatis的整合包
<!--Mybatis-Spring:Mybatis与Spring整合插件-->
< dependency >
    < groupId >org.mybatis </ groupId >
    < artifactId >mybatis-spring </ artifactId >
    < version >${mybatis.spring.version} </ version >
</ dependency >
1.4  Mysql驱动包和JDBC
<!--Mysql驱动-->
< dependency >
    < groupId >mysql </ groupId >
    < artifactId >mysql-connector-java </ artifactId >
    < version >${mysql.driver.version} </ version >
    < scope >runtime </ scope >
</dependency>
<!--Spring-JDBC:与Mybatis整合需要-->
< dependency >
    < groupId >org.springframework </ groupId >
    < artifactId >spring-jdbc </ artifactId >
    < version >${spring.version} </ version >
</dependency>
1.5  DBCP数据库连接池
<!--dbcp连接池-->
< dependency >
    < groupId >commons-dbcp </ groupId >
    < artifactId >commons-dbcp </ artifactId >
    < version >${dbcp.version} </ version >
</dependency>
1.6配置SpringMVC所需要的包
<!--Spring-MVC:SpringMVC组件-->
< dependency >
    < groupId >org.springframework </ groupId >
    < artifactId >spring-webmvc </ artifactId >
    < version >${spring.version} </ version >
</dependency>
1.7配置Servlet
< dependency >
    < groupId >javax.servlet </ groupId >
    < artifactId >javax.servlet-api </ artifactId >
    < version >${servlet.version} </ version >
    < scope >provided </ scope >
</dependency>
1.8额外需要的包
<!--Junit-->
< dependency >
    < groupId >junit </ groupId >
    < artifactId >junit </ artifactId >
    < version >${junit.version} </ version >
    < scope >test </ scope >
</ dependency >
<!--FastJson:高效率的Json处理工具-->
< dependency >
    < groupId >com.alibaba </ groupId >
    < artifactId >fastjson </ artifactId >
    < version >${fastjson.version} </ version >
</dependency>
2 项目结构


3 根据数据库,反向生成对应的pojo类,Mapper接口和Mapper.xml 
  步骤:①配置Mybatis反向生成的插件  < configurationFile >中配置用于反向生成文件 GeneratorConfigSimple.xml的路径
<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.5</version>
    <configuration>
        <configurationFile>src/main/resources/cn/qiancheng/ssmdemo/config/GeneratorConfigSimple.xml</configurationFile>
        <overwrite>true</overwrite>
    </configuration>
</ plugin >
②在 GeneratorConfigSimple.xml配置数据库信息
(文件在此)






          ③ 开始反向生成
4配置Spring文件ApplicationContext
步骤:①加载perporties文件
       ②扫描service中带注解的类
       ③声明注解
        ④创建数据源
          ⑤创建sqlSessionFactory的单例bean{
                    1配置数据源
                     2配置实体类的别名,默认为类型首字母小写
                    3指定Mapper.xml扫描}
          ⑥批量生成Mapper的代理类,名称为首字母小写
                    
 


5在SpringMVC.xml中配置MVC相关设置    
 
步骤:①扫描包中的Component和Autowire注解
     ②开启默认映射处理器和适配器
     ③开启静态资源处理(一般是关闭),开启的作用是可以通过路径访问到jsp文件
     ④配置视图处理器

6配置web.xml文件
步骤:①加载ApplicationContext.xml文件
     ②开启监听器
     ③POST编码过滤防止乱码
     ④配置DispacherServlet及初始参数
<? xml version ="1.0"  encoding ="UTF-8" ?>
< web-app  xmlns ="http://xmlns.jcp.org/xml/ns/javaee"
          xmlns: xsi ="http://www.w3.org/2001/XMLSchema-instance"
          xsi :schemaLocation ="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
          version ="3.1" >
    <!--加载ApplicationContext.xml-->
    < context-param >
        < param-name >contextConfigLocation </ param-name >
        < param-value >classpath:cn/qiancheng/ssmdemo/config/ApplicationContext.xml </ param-value >
    </ context-param >
    <!--开启监听器-->
    < listener >
        < listener-class >org.springframework.web.context.ContextLoaderListener </ listener-class >
    </ listener >
    <!--POST编码过滤-->
    < filter >
        < filter-name >characterEncoding </ 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 >characterEncoding </ filter-name >
        < url-pattern >/* </ url-pattern >
    </ filter-mapping >
<!--将所有的请求发送给DispatchServlet-->
    < servlet >
        < servlet-name >SpringMVC </ servlet-name >
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--配置DispaqServlet的初始参数-->
        < init-param >
            < param-name >contextConfigLocation </ param-name >
            < param-value >classpath:cn/qiancheng/ssmdemo/config/SpringMVC.xml </ param-value >
        </ init-param >
    </ servlet >
    < servlet-mapping >
        < servlet-name >SpringMVC </ servlet-name >
        < url-pattern >/ </ url-pattern >
    </ servlet-mapping >
</ web-app >

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用Maven搭建SSM框架的步骤如下: 1. 首先,确保你已经安装了Java和Maven,并且环境变量已经配置好。 2. 创建一个Maven项目: ``` mvn archetype:generate -DgroupId=com.example -DartifactId=myproject -DarchetypeArtifactId=maven-archetype-webapp ``` 3. 进入项目目录: ``` cd myproject ``` 4. 在`pom.xml`文件中添加SSM依赖: ```xml <dependencies> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.3.13.RELEASE</version> </dependency> <!-- Spring MVC --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.13.RELEASE</version> </dependency> <!-- MyBatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.7</version> </dependency> <!-- 数据库驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.26</version> </dependency> </dependencies> ``` 5. 创建Spring配置文件`applicationContext.xml`,配置Spring和MyBatis相关的内容。 6. 创建MyBatis的映射文件,定义数据库表的映射关系。 7. 创建Controller、Service和Dao层的Java类,编写业务逻辑和数据库操作。 8. 编译项目: ``` mvn compile ``` 9. 打包项目: ``` mvn package ``` 10. 部署项目: 将生成的war包部署到Web容器(如Tomcat)中即可。 这样,你就使用Maven成功搭建了一个SSM框架的项目。在实际开发中,你可能还需要配置数据库连接、日志等相关内容,具体根据项目需求进行配置和开发。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值