• SSM 整合


    整合后文件

    配置文件:

    1. spring与mybatis配置文件:applicatonContext.xml

    1. 导入数据库配置文件
    2. 配置数据源信息
    3. 配置事务管理器
    4. 开启事务注解
    5. 配置 mybatis 的 sqlSessionFactoryBean
    6. 配置 mapper 扫描器
    7. 扫描 service 
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd">
    <!--    导入数据库配置文件-->
        <context:property-placeholder location="classpath:config/db.properties"/>
    <!--    配置数据源-->
        <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
            <property name="driverClassName" value="${jdbc.driver}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            <property name="maxTotal" value="${jdbc.maxTotal}"/>
            <property name="maxIdle" value="${jdbc.maxIdle}"/>
            <property name="initialSize" value="${jdbc.initialSize}"/>
        </bean>
    <!--    事务管理器-->
        <bean id="transactionManager" 
              class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
    <!--    开启事务注解-->
        <tx:annotation-driven/>
    <!--    配置 Mybatis 的 sqlSessionFactoryBean-->
        <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="configLocation" value="classpath:config/mybatis-config.xml"/>
        </bean>
    <!--    配置 mapper 扫描器-->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.zhh.dao"/>
        </bean>
    <!--    扫描 service-->
        <context:component-scan base-package="com.zhh.service"/>
    </beans>
    
    applicationContext.xml
    applicationContext.xml

    2. springMVC 配置文件:springMVC-config.xml

    1. 包扫描,扫描 controller 注解
    2. 加载注解qvdong
    3. 配置视图扫描器,配置前缀后
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--    包扫描器,扫描 controller 注解-->
        <context:component-scan base-package="com.zhh.controller"/>
    <!--    加载注解驱动-->
        <mvc:annotation-driven/>
    <!--    配置视图解析器-->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    </beans>
    
    springMVC-config.xml
    springMVC-config.xml

    3. web.xml

    1. 配置 spring 文件监听器 org.springframework.web.context.ContextLoaderListener
    2. 添加编码过滤器 org.springframework.web.filter.CharacterEncodingFilter
    3. 配置springMVC控制器 org.springframework.web.servlet.DispatcherServlet
    <?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_4_0.xsd"
             version="4.0">
    <!--    配置 spring 文件监听器-->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:config/applicationContext.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    <!--    编码过滤器-->
        <filter>
            <filter-name>encoding</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>encoding</filter-name>
            <url-pattern>*.action</url-pattern>
        </filter-mapping>
    <!--    配置 springMVC 前端核心配置器-->
        <servlet>
            <servlet-name>springMVC</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:config/springMVC-config.xml</param-value>
            </init-param>
            <!--服务器启动后立刻加载springMVC-->
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>springMVC</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    </web-app>
    
    web.xml
    web.xml

     4. db.properties

    jdbc.driver=org.mariadb.jdbc.Driver
    jdbc.url=jdbc:mariadb://localhost:3306/boot_crm?serverTimezone=UTC
    jdbc.username=root
    jdbc.password=000000
    jdbc.maxTotal=30
    jdbc.maxIdle=10
    jdbc.initialSize=5
    db.properties

    5. log4j.properties

    ### direct log message to stdout ###
    log4j.appender.stdout.Target = System.out
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern =  %d{ABSOLUTE} %5p %c{1}:%L - %m%n
    
    log4j.rootLogger=INFO, stdout
    log4j.properties

    6. mybatis.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <!--
    <configuration>
        <typeAliases>
            <package name="com.zhh.model"/>
        </typeAliases>
    </configuration>-->
    <configuration>
    
    </configuration>
    mybatis.xml

    7. mapper.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="">
    </mapper>
    mapper.xml
    • before around
    • before
    • === 函数执行 ===
    • after around
    • after
    • after return
    • before around
    • before
    • === 抛出异常 ===
    • after
    • after throwing

     

     

     

    翻译 朗读 复制 正在查询,请稍候…… 重试 朗读 复制 复制 朗读 复制 via 谷歌翻译(国内)

  • 相关阅读:
    上传视频到七牛云django端实现
    课程全文检索接口
    搜索引擎工作原理
    创建订单并生成支付链接接口
    支付宝支付流程
    通过课程查询商品信息
    如何使用 RESTClient 调试微信支付接口
    关于HTML使用ComDlg ActiveX 无法弹出相应对话框的问题1
    Android自定义View的实现方法,带你一步步深入了解View(四)
    Android视图状态及重绘流程分析,带你一步步深入了解View(三)
  • 原文地址:https://www.cnblogs.com/zhangzixian/p/11801623.html
Copyright © 2020-2023  润新知