zoukankan      html  css  js  c++  java
  • SpringMVC10——SSM整合

    SSM整合
    Spring--SpringMVC--MyBatis
    1.Spring--MyBatis: 整合将SqlSessionFactory交给Spring
    2.Spring--SpringMVC: 将 Spring-SpringMVC各自配置一遍
     
    步骤:
    1.jar包;
    2.类-表;
    3.整合时,conf.xml可省,放入spring配置文件applicationContext.xml;
    4.通过mapper.xml将类、表建立映射关系;
    5.配置Spring配置文件:applicationContext.xml;
    web.xml;
    <!--web项目中引入Spring-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    6.使用Spring整合myBatis:将SqlSessionFactory交给Spring
    方式:扫描包
    <!--使用Spring整合myBatis-->
    <!--第三中方式生成mapper对象
        批量产生mapper对在ioc中的id值默认为接口名,接口名=id,接口名首字母小写
    -->
    <bean id="mappers" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--将SqlSessionFactory交给Spring-->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
        <!--指定批量产生那个包中的mapper对象-->
        <property name="basePackage" value="org.ghl.mapper"></property>
    </bean>
    7.继续整合SpringMVC:将SpringMVC加入项目即可
    a.加入SpringMVC需要的jar:
    spring-webmvc.jar
    b.给项目加入SpringMVC支持
    <!--整合SpringMVC-->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext-controller.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    c.编写SpringMVC配置文件:applicationContext-controller.xml
    <!--配置视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/views/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
     
    <!--SpringMVC标配-->
    <mvc:annotation></mvc:annotation>
    
     
     
     
  • 相关阅读:
    PHP的常用框架有哪些?
    Django中反向生成models
    Django中使用django_debug_toolbar
    Django日志系统
    RESTful接口规范
    Django restframework
    Mysql数据备份与还原
    CORS解决跨域问题
    Linux下Python2升级Python3
    Django+Uwsgi+Nginx部署
  • 原文地址:https://www.cnblogs.com/ghlz/p/13510949.html
Copyright © 2011-2022 走看看