SSM and open source frameworks ------ interview guide

1.MyBatis:

1.1MyBatis important components:

  • Mapper Configuration: The entity class Student.java - Data Sheet student, XML or annotation
  • Mapper Interface: DAO layer interface. (Just write interfaces without writing a class that implements: the need to follow the conventions)
  • Mapper interfaces need to follow when writing conventions:

    1. SQL method name and the id value profile (studentMapper.xml) must be the same

    2. The method of input parameters, and must be of the type of SQL parameterType same profile;

    3. The return value of the method, and must be of the type resultType same SQL profile

    SQL Profiles

  • <select id="queryStudentByNo"  parameterType="int"  resultType="lanqiao.entity.Student" >
        select * from student where stuNo = #{stuNo}
    </select>

    interface

  • public interface StudentMapper
    {
      Student queryStudentByNo(int stuNO)
       List<Student> queryStudentByNo()
    }

    special:

    ParameterType 1. If not present, represents a non-parametric method is

    2. If there is no resultType, it represents the return value is void

    3. If the return value is a collection type, the actual resultType still the element type, rather than a collection type.

1.2MyBatis development of common objects

1.SqlSessionFactory: SqlSesssion factory. Generating SqlSesssion objects openSession SqlSesssion in (): by SqlSessionFactory.

2.SqlSesssion: SqlSesssion objects (similar to the JDBC Connection)

3.Executor: MyBatis all Mapper statement execution is carried out by Executor

1.3MyBatis four core subject

1.StatementHandler (responsible sql statement): processed database select ... from where id = # {} ..

2.PrameterHandler (responsible for parameters in sql): Process parameter object in SQL

3.Executor

4.ResultSetHandler: processing SQL returns result sets

1.5MyBatis four processor

StatementHandler、PrameterHandler、ResultSetHandler

A left: TypeHandler (type converter)

1.6 one to one, one to many, lazy loading

One to One

  

Use <resultMap> in <association>
One lazy loading:
Use <resultMap> in <association> select attribute specified delay loading sql statement
 <resultMap>    
        <Association select = "lazy loading sql statement">
        <<association>>
</resultMap>

Many:

    The one in the association changed collection

2.Spring

IOC / DI: Inversion of Control / DI

  Objective: decoupling

  Student2 student = new Student2 () will result in the use of new highly coupled -> Mode Factory

  Class -> new -> Object

  Class -> Factory Mode -> Object, decoupling can be achieved, the question is: need to write your own factory

  IOC: IoC to help us provide a factory. 1. Fill objects (Configuration [xml, comments]) to get the object from the plant 2 plants

  Summary: Ioc allows us to create objects through the "configuration mode"

AOP: Aspect-Oriented Programming

  Of OOP (object oriented) supplement, not replace

  

 

 The benefits of using AOP

 

 

 

 

  Use the actual scene of AOP:

  Logs, security and unity check

Spring uses those design patterns

Factory pattern: create bean, bean acquisition

Singleton / prototype pattern: When creating bean, set the scope, singleton / prototype

Listening mode: Custom publishing time, listening mode. As ApplicationListener, when an action is triggered, it will automatically execute a notification.

Chain of Responsibility pattern: AOP

Strategy Mode: Create Agent

 

3.SpringMvc

SpringMvc implementation process

 

 

 

4.SpringBoot

The main functions: automatic assembly

Before (without spring boot), needs its own configuration framework configuration files.

Case spring, mybatis, SSM integration need to write a lot of configuration files.

If Spring Boot, the configuration may be omitted. Benefits: The development focus on business logic rather than on the configuration.

The principle of automatic assembly? Convention over configuration (core: some configuration features, front to achieve good underlying source code)

Two automatic assembly features:

1. Version Arbitration Center: Therefore, after the introduction of dependency, do not write the version number. Benefits: 1. do not mind 2. avoid conflict (preventing the introduction of more attracted, conflict due to incompatible versions of each depend caused)

2. Provide a lot of starter (Scene starter): Bulk jar.

Assuming that the development of web projects (json.jar tomcat.jar hibernate-validator.jar, spring-web.jar ...) => spring-boot-starter-web.

以后使用web项目,只需要引入spring-boot-starter-web

自动装配的应用时: @EnableAutoConfiguration 就是springboot提供自动装配的 注解。

 

5.Spring Cloud

Spring Cloud:微服务治理框架

  Eureka:服务注册中心,类似于dubbo中的zookeeper

 

 需要注意:Eureka Client有两个角度:如果站在eureka来看,是一个 客户端;如果站在系统角度来看,是一个服务端。

 

6.Ribbon

客户端负载均衡工具

 

 

7.Feign

声明式客户端负载均衡工具

Feign是建立在Ribbon之上。

Feign与Ribbon的区别: Ribbon面向URI地址的;Feign面向接口的

 

8.熔断器

熔断器:Hystrix

 

 

 

解决服务雪崩:熔断器

 

 

 

备用方法b2通常是错误提示或者日志记录

@HystrixCommand(fallbackMethod="b2")
public void a()
{
    
    b();//远程
}

puyblic void b2()
{
    ...
    
}

 

Guess you like

Origin www.cnblogs.com/xp0813/p/12303809.html