spring boot + ssm frame face questions

MyBatis description:
MyBatis is a first class persistence framework, support for custom SQL, stored procedures and advanced mappings.
MyBatis virtually eliminates all JDBC code and manual setting parameters and a retrieval result.
MyBatis can use simple XML configuration and mapping primitives,
the Map interfaces and Java POJO (Plain Old Java Objects) to database records

1. What is Mybatis?
(1) Mybatis is a semi-ORM (object-relational mapping) framework that encapsulates the internal JDBC, SQL statements only need to focus on the development itself, does not need to spend energy to handle the loading drive, create a connection, create complicated process statement and so on. Programmers write directly to the original ecology sql, sql execution performance can be tightly controlled, high flexibility.
(2) MyBatis annotations may be using XML or native configuration and mapping information to map POJO database records, to avoid almost all JDBC code and manual setting parameters and obtaining the result set.

2, Mybaits advantages of:
(1) to provide XML tags, support the preparation of dynamic SQL statements can be reused.
(2) Compared with the JDBC, reducing the amount of code more than 50%, eliminating redundant code JDBC large, no manual switch is connected;
(. 3) to connect to the database using JDBC MyBatis, so long as the are supported by JDBC database MyBatis support
(4) can be well integrated with the Spring;
(5) to provide a mapping label, field support ORM object relationship mapping database; providing an object-relational mapping label, object-relational component maintenance support.

Shortcomings 3, MyBatis framework :
the preparation work (1)
(2) SQL statement depends on the database, resulting in poor portability database, the database can not be replaced

The basic workflow 4.mybatis
1 reads the configuration file, the configuration file contains the database information and the connection map file or Mapper Mapper package path.
2. With this information you can create SqlSessionFactory, SqlSessionFactory the life cycle of a program level, established when the program is running, the program ends when the demise of
3.SqlSessionFactory establish SqlSession, the purpose of the implementation of sql statement, SqlSession is the process level, a method establishment, the method ends should be closed
4. when a user to use a configuration mapper.xml file, parses sql MyBatis first tag corresponding dynamic database sql statement forms, and encapsulated into MapperStatement object, and then by the executor sql injection execution database and returns the result.
5. The result returned by the mapping, packaged java object

5. There are several interface binding implementation, namely how to achieve?
Interface binding implemented in two ways,
(1) Notes binding: the interface is in the method above @ Select @ Update which contains notes and other Sql statement binding
(2) Another is to write SQL by binding xml inside, in this case, to specify the xml mapping file inside the namespace must be a full path name of the interface.

6.mybatis development "trio"
(. 1) Generator-code generation .Mybatis
mybatis-generator is a good use mybatis automatic code generation tool. Manually write a class entities and mapper xml configuration file there will be a lot of trouble, use mybatis-generator requires only a simple configuration can be done
(2) .Mybatis-plugin plugin
provides Mapper interface configuration file in the corresponding SQL navigation
edit XML auto-completion when a file
automatically checks for conflicts Mapper XML file ID
attribute value is automatically checks Mapper XML file errors
(3.). Mybatis-PageHelper pagination plug-in

7. Cache speaking at the MyBatis
MyBatis cache into cache and secondary cache,
cache session on the inside, there is a default, the secondary cache in its namespace, is on by default,
use two properties required level cache implements serializable class serialization interface (used to save the state of the object), it may be disposed on mapping file

8.#{}和${}的区别是什么?
#{}是预编译处理,${}是字符串替换。
Mybatis在处理#{}时,会将sql中的#{}替换为?号,调用PreparedStatement的set方法来赋值;
Mybatis在处理${}时,就是把${}替换成变量的值。
使用#{}可以有效的防止SQL注入,提高系统安全性

9. When the field names in the entity class attribute name and the table is not the same, how do?
Item 1: by defining a field name in the query sql statement alias, so that the property name alias field names and entities of the same class
of two kinds: one correspondence by mapping field names and the name of the entity class attributes relationship

10. Why Mybatis semi-automatic ORM mapping tools? Where it differs is in automatic?
Hibernate ORM mapping tool is fully automatic, with the Hibernate query associated object or collection object can be directly obtained according to an object-relational model, it is fully automatic. And Mybatis when querying the associated object or collection of objects associated with the need to manually write sql to complete, so called semi-automatic ORM mapping tools.

Springmvc advantages of:
(1) technologies may support various views, not just the JSP;
(2) integrated with the Spring framework (e.g. IoC container, the AOP, etc.);
(3) a clear role assignment: front-end controller (DispatcherServlet ), maps the request to the processor (HandlerMapping), the adapter processor (HandlerAdapter is), view resolver (ViewResolver).
(4) supports a variety of resource mapping policy request

1. What is Spring MVC? SpringMVC your understanding of the simple introduction?
The Spring MVC is a Java implementation of the type of request-driven MVC design pattern lightweight Web framework, based on
the decoupling layer web duty by the Model, View, Controller separation,
the complex web application into logical sections clearly simplify the development, reduce errors, to facilitate engagement between the inner group of developers

2, SpringMVC process?
(1) The user sends a request to the front-end controller the DispatcherServlet;
(2) the DispatcherServlet after receiving the request, the call processor HandlerMapping mapper request to obtain the Handle;
(. 3) the processor finds particular mapping processor generation processing according to the request url blocker object and a processor (if it is generated) collectively returned to the DispatcherServlet;
(. 4) to call the DispatcherServlet HandlerAdapter processor adapter;
(. 5) adapted through HandlerAdapter specific call processor (Handler, also called back-end) ;
(. 6) perform complete Handler returns ModelAndView;
(. 7) Handler HandlerAdapter is the execution result is returned to ModelAndView the DispatcherServlet;
(. 8) to the DispatcherServlet ModelAndView pass parser parses ViewResolver view;
return after DETAILED view (. 9) analytical ViewResolver;
(10 ) view of the DispatcherServlet render view (model data coming filled view)
(. 11) in response to the DispatcherServlet user.

Here Insert Picture Description

3, Spring MVC's major components?
(1) DispatcherServlet front controller (not require programmers)
action: receiving a request, a response result, the equivalent of the transponder, with DispatcherServlet reduces the coupling between the other components.
(2) the HandlerMapping mapper processor (not require programmers)
effect: The request URL to locate Handler
(. 3) Processor Adapter HandlerAdapter
NOTE: To HandlerAdapter accordance with the rules required to write in the preparation of the Handler, so that the adapter HandlerAdapter before you can go right to perform Handler.
(4) Handler Processor (programmers needed)
(5) ViewResolver view resolver (not require programmers)
action: parsing view, a view of the logical name resolves to a real view (View)
(. 6) View View (requires programmers to develop JSP)
view is an interface, its implementation class support different view types (jsp, freemarker, pdf, etc.)

4.Spring MVC exception handling?
A: You can throw an exception Spring framework, is handled by the Spring framework; we only need to configure a simple exception handler, Tim can view the page in the exception handler.

5.SpringMVC how to set redirection and forwarding?
(1) Forward: the return to the previous value plus "forward:", such as "Forward:? User.do method4 name ="
(2) Redirection: In return to the previous value plus "redirect:", such as "redirect: http: / /www.baidu.com "

6.SpringMvc how AJAX and call each other?
Jackson by the frame can be put inside the Java objects directly into Json Js identifiable objects. Specific steps are as follows:
(1) was added Jackson.jar
(2) arranged json mapping in the configuration file
(3) Ajax receiving method which can directly return Object, List, etc., but the front @ResponseBody To add annotations.

7.SpringMvc controller is not a singleton, and if so, what is the problem, how to solve?
A: Yes, a singleton, so when in multithreaded access have thread-safety issues, do not use synchronization, will affect the performance of the solution is not written in a field controllers inside.

8, SpringMvc the return value of the function what is?
A: The return value can have many types, there String, ModelAndView. ModelAndView the view class and data are merged together, but generally the String better.

9, SpringMvc what objects to transfer data from the back to the front desk?
A: By ModelMap object, you can call the put method in which the object, the object is added to the inside, the front desk you can get by el expressions.

10, how to put data into the Session ModelMap inside there?
A: You can add @SessionAttributes annotation, which contains the string is to be placed inside the session key in a class above.

spring characteristics of
the core technology: dependency injection, events, resources, i18n, validation, data binding, type conversion, SpEL, AOP.
Test: mock objects, TestContext framework, Spring MVC test, WebTestClient.
Data Access: Transaction, DAO support, JDBC, ORM, marshaled XML.
Spring MVC and Spring WebFlux Web framework.
Integration: Remoting, JMS, JCA, JMX, e-mail, tasks, scheduling, caching.
Language: Kotlin, Groovy, a dynamic language.

What 1.Spring is?
The Spring is a lightweight IoC container and AOP framework. To provide basic services for a Java application framework that aims to simplify the development of enterprise applications, it allows developers only need to care about business needs. There are three common configurations: XML-based configuration, annotation-based configuration, Java-based configuration.
Mainly consists of the following modules:
the Spring Core: Core library, IOC provide services;
the Spring Context: provide a framework for Bean-style access methods, as well as enterprise-class features (JNDI, scheduled tasks, etc.);
the Spring AOP: AOP services;
the Spring DAO : JDBC abstraction, and simplifies data access exception handling;
the Spring ORM: support for existing ORM frameworks;
the Spring Web: provides basic comprehensive Web-oriented features, such as multi-file upload;
the Spring MVC: to provide for Web application of Model-View-Controller implementation.

2, Spring advantage?
(1) spring design is a low-invasive, low pollution code;
(2) the DI Spring mechanism dependencies between objects referred frame processing to reduce coupling component;
(. 3) provides the Spring AOP technology, supports centralized management of some common tasks, such as security, transactions, logs, rights, etc., in order to provide better reuse.
(4) spring for mainstream application framework provides integrated support.

3, Spring understanding of AOP :
           of OOP object-oriented, allowing developers to define vertical relations, but is used to define a transverse relationship, resulting in a large number of duplicate code reuse detriment of each module.
           The AOP, generally referred to as aspect-oriented, object-oriented, as a supplement,Independent of those for business, but the impact on public behavior and a plurality of logical objects, extraction and packaged as a reusable modulesThis module is named "slice" (Aspect), to reduce the code system is repeated, reducing the coupling between modules, while increasing the maintainability of the system. Permissions can be used for authentication, logging, transaction processing.
           The key is to achieve AOP proxy mode, AOP proxy agent is divided into static and dynamic agency. Static agent representatives AspectJ; dynamic proxies Spring AOP places represented.
(1) AspectJ is static agent to enhance the so-called static agents, AOP is the AOP framework to generate proxy classes at compile time, it is also called enhanced when compiled, he will be AspectJ (cut) woven into Java byte at compile time code, when the object after running the AOP is enhanced.
(2) Dynamic Spring AOP agent used, the so-called dynamic proxy AOP framework that is not to modify the byte code, but each generate a temporary AOP runtime objects in memory as a method, this object contains AOP audiences all the way and make a specific cut-off point in the enhancement process, and the callback original object.
           Spring AOP dynamic proxy There are two main ways, JDK dynamic proxies and CGLIB dynamic proxies:
①JDK dynamic agent provides for only interface does not support proxy class. InvocationHandler core interfaces and Proxy classes, called through InvocationHandler invoke () method reflection code in the target class, dynamically cross woven together and business logic; Next, using Proxy InvocationHandler dynamically create an instance of an interface of compliance, generate a proxy object target class.
② If the agent had not realized InvocationHandler interfaces, then Spring AOP will choose to use dynamic proxy CGLIB target class. CGLIB (Code Generation Library), code generation is a class library, a dynamically generated object is a subclass of the specified class at runtime, and wherein the cover and the specific method of adding a reinforcing code to achieve AOP. CGLIB by inheritance way to do dynamic proxy, so if a class is marked as final, it can not be used for dynamic CGLIB agent.
(3) dynamic and static proxy agent difference is the generation timing AOP proxy object, relatively static AspectJ proxy mode with better performance, but requires a specific compiler AspectJ processing, and do not need specific Spring AOP compiler processing.

4, Spring's IoC understood:
(1)IOC is the inversion of controlRefers to the transfer of control to create an object, the object previously created by the initiative and opportunity to control their own, and now the shift in power to the Spring container by container to create and manage instances each instance based on profile dependencies between, loose coupling between objects and objects, but also conducive to the alternate functions.DI Dependency InjectionAnd inversion control are described with the same concept of different angles, i.e., application dependent IoC container at runtime to dynamically injecting a subject in need of external resources.
(2) the most intuitive expression is, IOC make creating objects do not have to go to new, and can be automatically produced by the spring, reflecting mechanism uses java and dynamic to create objects and managed objects at run time based on the configuration file, and call the object method.
(3) Spring's IOC injection three ways: constructor injection, the setter method of injection, injection in accordance with annotations.

IoC让相互协作的组件保持松散的耦合,而AOP编程允许你把遍布于应用各层的功能分离出来形成可重用的功能组件。

5, please explain Spring Bean's life cycle?
First talk about Servlet life cycle: instantiating, initially the init, receiving a request-Service, the destruction of the destroy;
the Spring context Bean life cycle is similar, as follows:
(1) Example of Bean:
For BeanFactory container, When a client requests a to the vessel when the bean has not been initialized, initialization or when the bean is to be injected dependent on another has not been initialized, the container will call createBean instantiated. For ApplicationContext container, when after the container starts by acquiring information BeanDefinition object, instantiates all of the bean.
(2) Set the object properties (dependency injection):
Object instantiation after BeanWrapper are encapsulated in objects, followed, Spring dependency injection is completed in accordance with the interface information BeanDefinition setting properties provided by BeanWrapper.
(3) processing Aware Interface:
Next, Spring will detect whether the object implements xxxAware interface and injection-related xxxAware instance to the Bean:
① If Bean has been achieved BeanNameAware interface calls setBeanName its implementation (String beanId) method, passing the Spring id value here is the configuration file of Bean;
② if the Bean has been achieved BeanFactoryAware interface calls setBeanFactory its implementation () method, passing the Spring factory itself.
③ If Bean has been achieved ApplicationContextAware interface calls setApplicationContext (ApplicationContext) method, passing in the Spring context;
(4) BeanPostProcessor:
If you want to make some Bean custom processing, it allows Bean to achieve a BeanPostProcessor interface, it will It calls postProcessBeforeInitialization (Object obj, String s) method.
(5) InitializingBean the init-method:
If Bean configured init-method property in the Spring configuration file, it will automatically call the initialize method of its configuration.
(6) If the Bean implements BeanPostProcessor interface will be called postProcessAfterInitialization (Object obj, String s) method; Since this method is called at the end of Bean initialization, so it can be applied to memory or cache technology;

以上几个步骤完成后,Bean就已经被正确创建了,之后就可以使用这个Bean了。

(7) DisposableBean:
When Bean is no longer needed, it will clean-up stage, if the Bean implements this interface DisposableBean, calls the destroy () method of its implementation;
(8) Method, the destroy-:
Finally, if the Bean Spring configuration configure the destroy-method property, the destruction of its configuration method is called automatically.

6, explanation Spring supports several bean scope.
Spring bean container can be divided into five ranges:
(. 1) Singleton: By default, each container is only one instance of the bean, the mode is maintained by a single embodiment BeanFactory itself.
(2) prototype: a request instance for each bean.
(3) request: Create an instance for each request for a network, after the completion of the request, the bean will fail and garbage collected.
(4) session: the request is similar to the range, to ensure that each session has an instance of the bean, after the session expires, bean failure will follow.
(5) global-session: global scope, global-session related and Portlet application. When your application deployment in the Portlet container, it contains a lot portlet. If you want to declare all of the portlet shared global memory variables, then it needs to be stored in global variables in the global-session. Servlet session scope and global scope in the same effect.

7, Singleton Beans Spring Framework is thread-safe it?
Spring framework does not carry out any processing of the multi-thread package singleton bean. About singleton bean thread safety and concurrency issues developers need to get their own. But in fact, most of the Spring bean is not mutable state (such as Serview class and the DAO class), so in a way that singleton bean Spring is thread-safe. If you have a variety of bean state, then (such as View Model objects), it is necessary to ensure their own security thread. Most simple solution is to polymorphic scope of the bean by the "singleton" is changed to "prototype".

8.Spring injection based on the bean xml ways:
(. 1) the Set injection method;
(2) constructor injection: ① By setting parameter index position; ② setting parameter type by type;
(3) static factory injection;
(4 ) examples of the plant;

9.Spring automatic assembly :
In the spring, the object without having to find or create their own associated with other objects, the container is responsible for the need to cooperate with each other giving each object object reference, use autowire to configure automatic loading mode.
In the Spring framework consensus xml configuration automatic assembling 5 kinds:
   (. 1) NO: The default mode is not the automatic assembly, the assembly is performed manually setting bean ref attribute.
   (2) byName: name of the bean by automatic assembly, the same as if a bean property of the bean to another name, to carry out automatic assembly.
   (3) byType: automatically assembled by the data type parameter.
   (4) constructor: using the constructor assembly, and the parameters are assembled by the constructor byType.
   (5) autodetect: automatic detection, if the constructor, construct assembled by automatic manner, or using automated assembly byType manner.

10. Spring AOP few terms to explain the inside of:
   (1) cut (Aspect): the extracted common module, may cross multiple objects. In Spring AOP, aspects are implemented using class (style based mode) or @AspectJ annotation to be implemented in the general category.
   (2) a connection point (Join point): refers to a method, in Spring AOP, a connection point always represents a method execution.
   (3) a notification (Advice): a particular action join point (Join point) executing on. Different types of advice, including "around", "before" and "after" and the like notified. Many AOP frameworks, including Spring, are based on advice as an interceptor model, and maintain a connection with the center point of the interceptor chain.
   (4) entry point (Pointcut): refers to the starting point we have to define which intercept Join point right. By pointcut expression specified intercept method, such as specifying interception add *, search *.
   (5) into (Introduction) :( type declarations also referred to as an internal (inter-type declaration)). Declare additional methods or certain types of fields. Spring allows the introduction of new interfaces (and a corresponding implementation) to any object in the proxy. For example, you could use an introduction to the bean implementation IsModified interface, to simplify caching.
   (6) target object (Target Object): being notified by one or more section (aspect) (advise) object. Some people call it being notified (adviced) objects. Since Spring AOP is achieved by running a proxy, this object is always to be a proxy (proxied) objects.
   (7) weaving (Weaving): refers to the enhancement applied to the target object to the process of creating a new proxy object. Spring is done at runtime weaving.
Concept pointcut (the pointcut) and the connection point (join point) matches the AOP is the key, which makes it different from the other AOP offering only interception of the old technology. Pointcuts enable (the advice) independently of the level of OO. For example, to provide a statement transaction management around advice can be applied to a set of objects across a plurality of methods (e.g., all business service layer operations).
Here Insert Picture Description

Spring boot feature :( six features)
to create a separate Spring applications
directly embedded Tomcat, Jetty or Undertow (no need to deploy WAR files)
provide a "Getting Started" to simplify the build configuration dependencies
automatically configured as Spring and third-party libraries
offer production-ready functions such as indicators, health checks and externalize configuration
absolutely no code generation and does not require XML configuration

1.Spring Boot advantages:
independent operation:
automatic configuration
no XML configuration code generation and
application monitoring
2.Spring Boot drawback
though approachable, but if you do not understand the principle, a problem would be more difficult.

3. What is the Spring Boot?
Spring Boot is a sub-project of the Spring open source organizations, is Spring component stop solution, the main difficulty is to simplify the use of Spring, Jane, heavy xml configuration, offers a variety of starters, custom during operation configuration, developers can quickly get started

4.SpringBoot autoconfiguration principle
(1), when the application starts SpringBoot, which proceeds from the start of the main method.

@SpringBootApplication
public class SpringBoot02ConfigAutoconfigApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBoot02ConfigAutoconfigApplication.class, args);
    }
}

它主要加载了@SpringBootApplication注解主配置类,这个@SpringBootApplication注解主配置类里边最主要的功能就是SpringBoot开启了一个@EnableAutoConfiguration注解的自动配置功能。
(2)、@EnableAutoConfiguration作用:
它主要利用了一个
EnableAutoConfigurationImportSelector选择器给Spring容器中来导入一些组件。
@Import(EnableAutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration

4.Spring Boot 的配置文件有哪几种格式?它们有什么区别?
.properties 和 .yml,它们的区别主要是书写格式不同。

5.运行 Spring Boot 有哪几种方式?
1)打包用命令或者放到容器中运行
2)用 Maven/Gradle 插件运行
3)直接执行 main 方法运行

6.Spring Boot 的核心注解是哪个?它主要由哪几个注解组成的?
启动类上面的注解是@SpringBootApplication,它也是 Spring Boot 的核心注解 主要组合包含了以下 3 个注解:
1.@SpringBootConfiguration:组合了 @Configuration 注解,实现配置文件的功能。
2.@EnableAutoConfiguration:打开自动配置的功能,也可以关闭某个自动配置的选项,如关闭数据源自动配置功能: @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })。
3.@ComponentScan:Spring组件扫描。

7.Spring Boot 可以兼容老 Spring 项目吗,如何做?
可以兼容,使用 @ImportResource 注解导入老 Spring 项目配置文件。

8.你如何了解 Spring Boot 中的 Starters?
Starters可以了解为启动器,它包含了一系列可以集成到应用里面的依赖包,你可以一站式集成 Spring 及其余技术,而不需要四处找示例代码和依赖包。如你想使用 Spring JPA 访问数据库,只需加入 spring-boot-starter-data-jpa 启动器依赖就能使用了。
Starters包含了许多项目中需要用到的依赖,它们能快速持续的运行,都是一系列得到支持的管理传递性依赖。

9.Spring Boot 2.X What's new? And 1.X What is the difference?
Configuration changes
JDK version update
third-party libraries update
responsive Spring program supports
HTTP / 2 support
configuration properties bind
more improvements and enhancements

10 @ SpringBootApplication comments inside what is the use?
As Spring guidance document, @ SpringBootApplication annotation is equivalent to using both @ Configuration, @ EnableAutoConfiguration and @ComponentScan its default properties. Spring Boot allows developers to use instead of a single comment plurality of annotations. However, we all know, Spring provides loose coupling characteristics, we can use these features for each annotation based on project needs.

Published 12 original articles · won praise 4 · Views 930

Guess you like

Origin blog.csdn.net/weixin_43974466/article/details/104327698