首页 > 其他分享 >SSM各框架使用及整合

SSM各框架使用及整合

时间:2023-06-14 13:24:13浏览次数:25  
标签:说明 框架 方式 -- SSM 整合 注解 配置文件

spring

常用注解

 

配置文件说明

<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--扫描组件(除控制层)-->
    <context:component-scan base-package="com.atguigu.ssm">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--引入jdbc.properties-->
    <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>

    <!--配置数据源-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>

    <!--配置事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!--
        开启事务的注解驱动
        将使用注解@Transactional标识的方法或类中所有的方法进行事务管理
    -->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <!--配置SqlSessionFactoryBean,可以直接在Spring的IOC中获取SqlSessionFactory-->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--设置MyBatis的核心配置文件的路径-->
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
        <!--设置数据源-->
        <property name="dataSource" ref="dataSource"></property>
        <!--设置类型别名所对应的包-->
        <property name="typeAliasesPackage" value="com.atguigu.ssm.pojo"></property>
        <!--设置映射文件的路径,只有映射文件的包和mapper接口的包不一致时需要设置-->
        <!--<property name="mapperLocations" value="classpath:mappers/*.xml"></property>-->
    </bean>

    <!--
        配置mapper接口的扫描,可以将指定包下所有的mapper接口
        通过SqlSession创建代理实现类对象,并将这些对象交给IOC容器管理
    -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.atguigu.ssm.mapper"></property>
    </bean>

</beans>

 

springMVC

常用注解

 

配置拦截器

方式一:

    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/> <!-- 生效范围/**代表所有 -->
            <mvc:exclude-mapping path="/testRequestEntity"/> <!-- 不生效的范围-->
            <ref bean="fistInterceptor"></ref><!-- 使用哪个拦截器拦截 -->
        </mvc:interceptor>
    </mvc:interceptors>

  

方式二:

<mvc:interceptors>-->
    <bean class="com.atguigu.mvc.interceptors.FistInterceptor"></bean>对所有请求生效
</mvc:interceptors>-->

 

方式三:

<mvc:interceptors>-->
    <ref bean="fistInterceptor"></ref>
</mvc:interceptors>-->

 

  

方式二和方式三两种配置方式都是对DispatcherServlet所处理的所有的请求进行拦截

配置文件说明

<?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: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/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--扫描控制层组件-->
    <context:component-scan base-package="com.atguigu.ssm.controller"></context:component-scan>

    <!--配置视图解析器-->
    <bean id="viewResolver" class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
        <property name="order" value="1"/>
        <property name="characterEncoding" value="UTF-8"/>
        <property name="templateEngine">
            <bean class="org.thymeleaf.spring5.SpringTemplateEngine">
                <property name="templateResolver">
                    <bean class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
                        <!-- 视图前缀 -->
                        <property name="prefix" value="/WEB-INF/templates/"/>
                        <!-- 视图后缀 -->
                        <property name="suffix" value=".html"/>
                        <property name="templateMode" value="HTML5"/>
                        <property name="characterEncoding" value="UTF-8" />
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

    <!--配置默认的servlet处理静态资源-->
    <mvc:default-servlet-handler />

    <!--开启mvc的注解驱动-->
    <mvc:annotation-driven />

    <!--配置视图控制器-->
    <mvc:view-controller path="/" view-name="index"></mvc:view-controller>

    <!--配置文件上传解析器-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>

</beans>

 

Mybatis

配置文件说明

<?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>

    <!--
        MyBatis核心配置文件中的标签必须要按照指定的顺序配置:
        properties?,settings?,typeAliases?,typeHandlers?,
        objectFactory?,objectWrapperFactory?,reflectorFactory?,
        plugins?,environments?,databaseIdProvider?,mappers?
    -->

    <settings>
        <!--将下划线映射为驼峰-->
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>

    <plugins>
        <!--配置分页插件-->
        <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
    </plugins>

</configuration>

 

标签:说明,框架,方式,--,SSM,整合,注解,配置文件
From: https://www.cnblogs.com/mingbo-1/p/17479917.html

相关文章

  • jexcel_最简单的框架
    1. 固定数据的jexcel框架<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="test.aspx.cs"Inherits="web_page_ssc_test"%><!DOCTYPEhtml><htmlxmlns="http://www.w3.org/1999/xhtml"><......
  • 案例4 基于Excel的接口测试框架
    简单版读取以下格式excel(仅第一张Sheet),逐个发送接口,断言接口返回200,并将状态及错误信息写回Excel已知:Excel中接口编写格式规范如下url如果有查询参数,要写到url中,例如?a=1&b=2如果需要添加自定义请求头按key:value格式编写,:左右允许有空格,每行一个请求数据支持表单和JSO......
  • SSM框架学习之Spring浅谈(二)
    Spring常用注解@Controller:对应SpringMVC控制层,主要用户接受用户请求并调用Service层返回数据给前端页面。@Service:对应服务层,主要涉及一些复杂的逻辑,需要用到Dao层。@Component:通用的注解,可标注任意类为Spring组件。如果一个Bean不知道属于哪个层,可以使用@......
  • ASP.NET Core 6框架揭秘实例演示[38]:两种不同的限流策略
    承载ASP.NET应用的服务器资源总是有限的,短时间内涌入过多的请求可能会瞬间耗尽可用资源并导致宕机。为了解决这个问题,我们需要在服务端设置一个阀门将并发处理的请求数量限制在一个可控的范围,即使会导致请求的延迟响应,在极端的情况会还不得不放弃一些请求。ASP.NET应用的流量限制......
  • 微服务框架的学习路线
    一、微服务的大体架构二、微服务的学习路线 参考:1、微服务架构是什么?有哪些优点和不足? ......
  • 关于Qt **QNetworkAccessManager**、**QNetworkReply**、**QNetworkRequest**实现ftp
    实现的ftp下载需要反馈下载进度,但是代码得到的bytesTotal始终为-1,直到下载完成那一刻,才变成文件大小。于是分析qt5base的network部分代码:network/access/qnetworkaccessftpbackend.cpp文件中,有如下片段:voidQNetworkAccessFtpBackend::ftpRawCommandReply(intcode,constQStr......
  • SSM+Tomcat+J2EE开发的药店管理系统
    基于SSM的药店管理系统项目介绍......
  • 集合框架
    1.使用集合框架的缘由由于数组在创建时会默认定义数组长度,而数组长度固定不变,所以导致数组的赋值及创建会浪费内存空间,集合作为可以更改长度的“数组”,解决了内存浪费的现象。2.Java集合框架架构图(1)集合有两个父接口,Collection和Map(2)Collection有两个子接口List和Set(3)Li......
  • RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2 新增解压缩工具类ZipHelper
    在项目对文件进行解压缩是非常常用的功能,对文件进行压缩存储或传输可以节省流量与空间。压缩文件的格式与方法都比较多,比较常用的国际标准是zip格式。压缩与解压缩的方法也很多,在.NET2.0开始,在System.IO.Compression中微软已经给我们提供了解压缩的方法GZipStream。对于GZipSt......
  • RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2-新增记录SQL执行过程
    有时我们需要记录整个系统运行的SQL以作分析,特别是在上线前这对我们做内部测试也非常有帮助,当然记录SQL的方法有很多,也可以使用三方的组件。3.2版本我们在框架底层新增了记录框架运行的所有SQl过程保存到用户指定的地方以便分析查看,只需要在配置文件把配置项”LogSQL”设置为Tr......