ssm框架整合思路

本文详细介绍了SSM(Spring、SpringMVC、MyBatis)框架的整合过程,从dao层的pojo、mapper接口和sql映射文件配置,到service层的服务扫描和事务管理,再到controller层的注解驱动、视图解析和异常处理,最后是web.xml中的前端控制器和请求乱码处理。关键配置文件包括SqlMapConfig.xml、applicationContext-dao.xml、db.properties等。
摘要由CSDN通过智能技术生成

1、dao层
  1.1、必须数据:
       pojo(java实体)、mapper接口(dao接口)、sql映射文件(翻译为jdbc中的statement)
  1.2、配置文件:
       mybatis核心配置文件:SqlMapConfig.xml
          自定义别名
       spring整合mybatis配置文件:applicationContext-dao.xml
         数据源
         会化工厂
         mapper扫描(加载dao)
       其他配置:
         数据库信息:db.properties
         日志信息:log4j.properties
2、service层
  2.1、配置文件:
       注解扫描:@service(加载service)applicationContext-service.xml
       事务配置: ApplicationContext-trans.xml
3、controller层
  3.1、配置文件: springMVC.xml
       注解扫描:@controller(加载controller)
       注解驱动:自动加载最新的处理器映射器、处理器适配器
       视图解析器:
       自定义类型转化器:(挂载于注解驱动)
       文件上传解析器:
       json格式数据解析器:(若没有配置注解驱动,则需要显示的在处理器适配器挂载)
       全局异常处理器:
       自定义拦截器:
       静态资源放行:
       
4、web.xml web.xml
  4.1、spring监听器
  4.2、springMVC前端控制器
  4.3、post中文乱码请求

SqlMapConfig.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>
    <properties resource="db.properties"></properties>

    <typeAliases> 
        <!-- 定义单个pojo类别名
                type:类的全路劲名称
                alias:别名
         -->
        <!-- <typeAlias type="xx.xxxx.pojo.User" alias="user"/> -->

        <!-- 使用包扫描的方式批量定义别名 
        定以后别名等于类名,不区分大小写,但是建议按照java命名规则来,首字母小写,以后每个单词的首字母大写
        -->
        <package name="xx.xxx.pojo"/>
    </typeAliases>
</configuration>

applicationContext-dao.xml

<beansxmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo        
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 配置 读取properties文件 jdbc.properties -->
    <context:property-placeholderlocation="classpath:jdbc.properties"/>

    <!-- 配置 数据源 -->
    <beanid="dataSource"class="com.alibaba.druid.pool.DruidDataSource">
        &
  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值