SSM框架配置及知识点回顾

SSM框架配置及知识点回顾

springMVC+spring+mybatis


springMVC框架工作流程

1.页面发送一个HTTP请求,

2.dispatcherServlet接受到请求

3.HandlerMapping寻找控制器

4.Controller控制器发送业务

5.service接收到业务

6.ModleAndView返回结果集到DispatcherServlet

7.DispatcherServlet将结果集返回给页面渲染层

8.页面通过视图解析器InternalRourceViewResolver渲染后响应给页面


SpringMVC的框架配置

一丶(dispatcherServlet枢纽器)配置web.xml

需要的核心包:spring.jar,spring-web.jar , spring-webmvc.jar  ,commons-logging.jar  ,cglib-nodep.jar

1.spring的配置(监听)

org.springframework.web.contetx.Contex tLoaderListener

作用:随着web应用的启动而启动,只初始化一次,随着web应用的停止而销毁,可以做一些初始化的内容添加工作,设置一些基本内容,比如固定对象,监听数据库连接池DataSource的初始化等等

2.springMVC的配置(前端控制器环境)

        springMVC

        org-springframework.web.servlet.DispatcherServlet

        1  //默认项目一发布,便创建servlet

        springMVC

        /

3.指定spring-bean文件所在目录

        contextConfigLocation//约定名称,不可更改

        classpath:springmvc.xml//配置文件名路径


SSM框架配置及知识点回顾_第1张图片
Web.xml配置

二丶springMVC-servlet.xml配置

1.复制进bean配置文件

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"   

        xmlns:context="http://www.springframework.org/schema/context"   

  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 

      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 

      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 

      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

2.启动 spring MVC 注解

3.设置使用注解的类所在的jar包,开启包扫描

4.完成请求和注释的pojo映射(开启mvc注解式驱动)

5.配置springMVC视图解析器(InternalRourceViewResolver)

         //prefix 前缀

         //suffix 后缀


SSM框架配置及知识点回顾_第2张图片
SpirngMVC - Servlet.xml配置

Mybatis框架配置

一丶配置 .properties文件

1.新建  db.properties文件(数据库连接信息)

db.driverClass=com.mysql.jdbc.Driver //  数据库驱动

db.url=jdbc:mysql://127.0.0.1:3306/index //  jdbc:mysql:// ip地址:端口号 / 数据库名

db.username=root //  账号名

db.password=root //  密码

二丶spring.xml配置

需要的核心包:mysql-connector.jar , mybatis.jar , mybatis-spring.jar 

log4j.jar,  asm.jar  ,  slf4j.jar ,  javassist.jar

1.引入属性文件(引入 .properties)

2.配置数据源

        

        

        

        

3.配置SQLSessionFactory

        

4.配置mybatis接口扫描器MapperScannerConfigurer

        

        

5.配置Mybatis事物管理

        class="org.springframework.jdbc.datasource.DatasourceTransactionManager">


SSM框架配置及知识点回顾_第3张图片
Mybatis

你可能感兴趣的:(SSM框架配置及知识点回顾)