SpringMVC use and introduction mybatis

This week a major study SpringMVC use and mybatis Introduction

SpringMVC concept:

1.Spring Web MVC is based on Java implementation of the Web MVC request-driven type of lightweight design patterns Web framework

2. Use the MVC idea of architecture model, the web layer to decouple duty

3. based on a request using the request refers to the drive - response model

4. The purpose of the framework is to help us simplify development,

Spring Web MVC also to simplify our daily Web development.

SpringMVC principle:

 

 

 

Process Description:

1. The user sends a request to the server, the request is controlled Servelt DispatcherServlet Spring distal capture;

2.DispatcherServlet request URL parsing to obtain the requested resource identifier (URI). According to this then the URI, access to all relevant call HandlerMapping Handler configuration of the object (including objects and Handler object Handler corresponding interceptor), and finally returned as HandlerExecutionChain object;

The obtained 3.DispatcherServlet Handler selects an appropriate HandlerAdapter. (Note: If successful HandlerAdapter, this time will begin preHandler blocker (...) method)

4. Request extraction of model data is filled into the reference Handler, started Handler (Controller). Participate in the process of filling Handler, depending on your configuration, Spring will help you to do some extra work:

HttpMessageConveter: a request message (e.g. Json, xml data, etc.) into a subject, convert the object to the specified response information

Data conversion: conversion of the data request message. The String is converted into Integer, Double, etc.

Radicals of data: data format of the request message. As will be converted into a string of numbers formatted or formatted date

Data Validation: Verify the validity of the data length, format, etc., stored in the verification result BindingResult or Error

After 5.Handler executed, a return to the DispatcherServlet ModelAndView object;

The return ModelAndView selecting a suitable ViewResolver (Spring must be registered to the container ViewResolver) is returned to the DispatcherServlet;

7.ViewResolver combination of Model and View, to render the view

8. The rendering results returned to the client.

SpringMVC nine components

** MultipartResolver used by this servlet file upload parser * /

    private MultipartResolver multipartResolver;

    / ** LocaleResolver used by this servlet internationalization parser * /

    private LocaleResolver localeResolver;

    / ** ThemeResolver used by this servlet theme resolver * /

    private ThemeResolver themeResolver;

    / ** List of HandlerMappings used by this servlet contains mappings request class (which request to process by which class) * /

    private List<HandlerMapping> handlerMappings;

    / ** List of HandlerAdapters used by this servlet adapter; for execution controller (processor) of the target method * /

    private List<HandlerAdapter> handlerAdapters;

    / ** List of HandlerExceptionResolvers used by this servlet exception resolver * /

    private List<HandlerExceptionResolver> handlerExceptionResolvers;

    /** RequestToViewNameTranslator used by this servlet 转化器*/

    private RequestToViewNameTranslator viewNameTranslator;

    /** FlashMapManager used by this servletFlashMap 管理器 */

    private FlashMapManager flashMapManager;

/ ** List of ViewResolvers used by this servlet view resolver * /

private List<ViewResolver> viewResolvers;

 

Related jar package:

 

 

 

 

Interceptor works

Similar to filter an object, a processor for pre-processing and post-processing ( controller ) .

 

 

mybatis Introduction

 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 Java POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。

 

使用mapper接口方式必须满足:

1 映射文件的namespace的值必须是接口的全路径名称 比如:com.dpb.dao.UserMapper

2 接口中的方法名在映射文件中必须有一个id值与之对应。

3 映射文件的名称必须和接口的名称一致

MyBatis的功能架构:

我们把Mybatis的功能架构分为三层:

API接口层:提供给外部使用的接口API,开发人员通过这些本地API来操纵数据库。接口层一接收到调用请求就会调用数据处理层来完成具体的数据处理。 

数据处理层:负责具体的SQL查找、SQL解析、SQL执行和执行结果映射处理等。它主要的目的是根据调用的请求完成一次数据库操作。 

基础支撑层:负责最基础的功能支撑,包括连接管理、事务管理、配置加载和缓存处理,这些都是共用的东西,将他们抽取出来作为最基础的组件。为上层的数据处理层提供最基础的支撑。 

MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置(settings)和属性(properties)信息。文档的顶层结构如下:

configuration 配置

    properties 属性

    settings 设置

    typeAliases 类型别名

    typeHandlers 类型处理器

    objectFactory 对象工厂

    plugins 插件

    environments 环境

        environment 环境变量

            transactionManager 事务管理器

            dataSource 数据源

    databaseIdProvider 数据库厂商标识

mappers 映射器

Mybatis 的内置日志工厂提供日志功能,内置日志工厂将日志交给以下其中一种工具作代理:

  • SLF4J
  • Apache Commons Logging
  • Log4j 2
  • Log4j
  • JDK logging

 

Guess you like

Origin www.cnblogs.com/whymoney1000/p/10962862.html