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

SSM整合总结

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

SSM整合总结

整合思路

1、使用maven构建出项目环境
2、配置Spring,即搭建Spring环境
3、使用Spring整合springMVC
4、再使用spring整合mybatis
5、最后整合mybatis框架配置事务

创建数据库和表
use database;
创建maven工程
Spring框架环境搭建

1、在resouces资源文件目录下,创建applicationContext.xml文件
2、编写applicationContext.xml




    
    
        
        
    
    


SpringMVC环境搭建

1、在web.xml中配置DispatcherServlet前端控制器,加载springmvc.xml文件

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

2、在web.xml中配置DispatcherServlet过滤器解决中文乱码问题

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

3、在resouces下创建springmvc.xml配置文件



    
    
        
    

    
    
        
        
    
    
    
    
    
    
    

Spring整合SpringMVC框架

思考问题: 怎样去整合spring、springMVC?
怎样才算整合成功?

整合成功的表现:在Controller(SpringMVC)中能够成功调用service(Spring)对象中的方法。 tomcat启动后,由于在web.xml中配置的有前端控制器,web容器会加载springmvc.xml配置文件,在springmvc.xml配置文件中配置的扫描包只有controller,而spring.xml文件从头至尾就没有执行过,spring中的配置就不会被扫描,也就是没有将spring交到IOC容器中,所以,要在服务器启动时就加载spring配置文件。具体实践就是 监听器 listener

 
    
        org.springframework.web.context.ContextLoaderListener
    
 
    
        contextConfigLocation
        classpath:applicationContext.xml
    
MyBatis框架环境搭建
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/325225.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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