栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SSM整合完整配置文件,详细思路+附带源码(看完上手直接用)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SSM整合完整配置文件,详细思路+附带源码(看完上手直接用)

目录

 前言

1.新建项目

2.新建项目的文件夹

3.从web.xml入手

4.配置applicationContext.xml文件

5.配置springmvc.xml文件

6.总结

7.源码、源码、源码~


 前言

SSM整合可以使用多种方式,咱们选择XML + 注解的方式,不要觉得不妥,这样其实最便捷-


提示:以下是本篇文章正文内容,下面案例可供参考


1.新建项目

1.1:使用Macenwebapp Rightarrow  webapp

1.2:导入项目依赖(pom.xml), 由创建自动生成




  4.0.0

  com.Lsy
  ssm
  1.0-SNAPSHOT
  war

  ssm Maven Webapp
  
  http://www.example.com

  
    UTF-8
    1.7
    1.7
  

  
    
    
      junit
      junit
      4.11
      test
    
    
    
      mysql
      mysql-connector-java
      8.0.13
    
    
    
      javax.servlet
      javax.servlet-api
      3.1.0
      provided
    
    
    
      javax.servlet.jsp
      javax.servlet.jsp-api
      2.2.1
      provided
    
    
    
      com.alibaba
      fastjson
      1.2.47
    
    
    
      taglibs
      standard
      1.1.2
    
    
    
      javax.servlet
      jstl
      1.1.2
    
    
    
      org.projectlombok
      lombok
      1.16.22
    
    
    
      commons-dbcp
      commons-dbcp
      1.4
    
    
    
      org.mybatis
      mybatis
      3.4.6
    
    
    
      org.springframework
      spring-aop
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-aspects
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-beans
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-context
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-context-support
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-core
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-expression
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-jdbc
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-tx
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-web
      5.1.3.RELEASE
    
    
    
      org.springframework
      spring-webmvc
      5.1.3.RELEASE
    
    
    
      org.mybatis
      mybatis-spring
      1.3.2
    
    
    
      log4j
      log4j
      1.2.17
    
    
    
      aopalliance
      aopalliance
      1.0
    
    
    
      org.aspectj
      aspectjweaver
      1.8.13
    
    
      org.testng
      testng
      RELEASE
      compile
    
    
      org.apache.httpcomponents
      httpmime
      4.3.2
    

    
    
      com.github.pagehelper
      pagehelper
      5.1.2
    

    
    
      cn.hutool
      hutool-all
      5.3.6
    
  

  
    ssm
    
      
        
          maven-clean-plugin
          3.1.0
        
        
        
          maven-resources-plugin
          3.0.2
        
        
          maven-compiler-plugin
          3.8.0
        
        
          maven-surefire-plugin
          2.22.1
        
        
          maven-war-plugin
          3.2.2
        
        
          maven-install-plugin
          2.5.2
        
        
          maven-deploy-plugin
          2.8.2
        
      
    
    
      
        org.apache.maven.plugins
        maven-compiler-plugin
        
          8
          8
        
      
    
  

2.新建项目的文件夹

手动创建(java、resources),以及子包entity,mapper. .  具体如下      

3.从web.xml入手

注意事项:

3.1:加载spring.xml文件

3.2:乱码过滤器

3.3:监听器,加载spring的配置文件,applicationContext.xml,如果没有配置监听器,那么spring的配置文件只能放在webapp包下

3.4:加载springmvc.xml文件(优先加载)

下面是webxml文件代码:





    Archetype Created Web Application


    
    
        contextConfigLocation
        classpath*:applicationContext.xml
    

    
    
        characterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
    
    
        characterEncodingFilter
        /*
    

    
    
        org.springframework.web.context.ContextLoaderListener
    

    
    
        dispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath*:springmvc.xml
        
    

    
        dispatcherServlet
        /
    

    
    
        
    

4.配置applicationContext.xml文件

4.1:配置数据源

4.2:配置sqlsessionFactoryBean(数据源, mapper.xml位置, mybaits配置文件的位置,别名)

4.3:扫描Mapper接口(@Mapper)

4.4:扫描dao以及service的包

 代码报错也可能是顺序的问题,这里也得注意一下




    
    
    
    
        
    

    
    
    
        
        
        
        
    
    
    
    
    
        
        

        
        
        

        
        

        
        
    

    
    
        
    

    
    


里面用到一个db.properties配置数据库连接属性的文件…代码奉上:

driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=UTF-8&useUnicode=true&serverTimezone=GMT%2B8
username=root
password=root

5.配置springmvc.xml文件

5.1:扫包

5.2:注解驱动(能够让程序识别springmvc的注解@RequestMapping() )

5.3:视图解析器

 细心的同学可以发现pringmvc.xml文件里面的扫包applicationContext.xml文件里面也有,其实两者取一即可,但是也不会冲突,这里做个小提醒





    
    
    
    
    
    
        
        
    

6.总结

以上是SSM完整配置文件,往后就可以直接写dao层,service……整个配置文件下来的确是挺繁琐,感兴趣的同学可以往后深入研究,以后的springboot相对来说就减去了大部分繁琐的流程,OK ,能够坚持到这里的各位都是人才,说话又好听,敲的代码又好看,我超喜欢你们,所以,我要是哪里写错了,欢迎指出,还望不吝赐教!!!

7.源码、源码、源码~

考虑到C币问题,已分享至阿里云盘。

「CSDN文章」,点击链接保存,或者复制本段内容,打开「阿里云盘」APP ,无需下载极速在线查看,视频原画倍速播放。 链接:阿里云盘分享

啥?没有网盘账户?出门右转,秋名山决斗…

点我的链接下一个吧,好人一生平安

但是说句实在话阿里的话确实比baidu要良心那么一下,我是说某些重要的方面咯,就比如上传和下载速度……emmmm你们自己觉得吧

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/605468.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号