preface

Java Oop, Java Collections containers, Java exceptions, concurrent programming, Java reflection, Java serialization, JVM, Redis, Spring MVC, MyBatis, MySQL database, messaging middleware MQ, Dubbo, Linux, ZooKeeper, distributed & data structure and algorithm, etc. 25 thematic technical points, are all small editor in each big factory summary of the interview real questions, there have been many fans with this PDF to win many big factory offer. Today, here is a summary to share to everyone! [Finished]

The full version of the Java interview questions address: 2021 latest interview questions collection collection.

The serial number project content link
1 The middleware Java Middleware (2021) Juejin. Cn/post / 694870…
2 Micro service Java Microservices (2021) Juejin. Cn/post / 694906…
3 Concurrent programming Concurrent Programming in Java (2021 latest Edition) Juejin. Cn/post / 695053…
4 Java based Java Basics (2021) Juejin. Cn/post / 695062…
5 Spring Boot Spring Boot Interview Questions (2021 Latest edition) Juejin. Cn/post / 695137…
6 Redis Redis Interview Questions (2021 Latest edition) Juejin. Cn/post / 695166…
7 Spring MVC Spring MVC (2021) Juejin. Cn/post / 695166…
8 Spring Cloud Spring Cloud Interview Questions (2021) Juejin. Cn/post / 695245…
9 MySQL optimization MySQL optimize interview questions (2021 latest edition) Juejin. Cn/post / 695246…
10 JVM JVM Performance Tuning Interview questions (2021 Latest Edition) Juejin. Cn/post / 695246…
11 Linux Linux Interview Questions (2021 latest edition) Juejin. Cn/post / 695287…
12 Mybatis Mybatis (2021 latest Edition) Juejin. Cn/post / 695287…
13 Network programming TCP, UDP, Socket, Http Network programming interview (2021 latest edition) Juejin. Cn/post / 695287…
14 Design patterns Design Mode Interview Questions (2021 Latest edition) Juejin. Cn/post / 695544…
15 Big data 100 Big Data Interview Questions (2021 latest edition) Juejin. Cn/post / 695544…
16 Tomcat Tomcat Interview Questions (2021 Latest edition) Juejin. Cn/post / 695570…
17 multithreading Multithreaded Interview Questions (2021 Latest edition) Juejin. Cn/editor/draf…
18 Nginx Nginx_BIO_NIO_AIO interview Questions (2021 Latest edition) Juejin. Cn/editor/draf…
19 memcache Memcache Interview Questions (2021 latest edition) Juejin. Cn/post / 695608…
20 Java exception Java Exception Interview Questions (2021 Latest edition) Juejin. Cn/post / 695644…
21 The Java virtual machine Java Virtual Machine Interview (2021 latest edition) Juejin. Cn/post / 695658…
22 Java collection Java Set Interview Questions (2021 Latest edition) Juejin. Cn/post / 695684…
23 Git Git Git Command (2021) Juejin. Cn/post / 695692…
24 Elasticsearch Elasticsearch (2021 Latest Edition) Juejin. Cn/post / 695840…
25 Dubbo Dubbo Interview Questions (2021 Latest edition) Juejin. Cn/post / 695842…

Summary of a.

1. What is Spring MVC? What is your understanding of Spring MVC?

Spring MVC is a java-based request-driven Web framework that implements MVC design pattern. By separating model-view-controller, the Web layer decoups responsibilities, and divides complex Web applications into logically clear parts, simplifying development, reducing errors, and facilitating cooperation among developers within the group.

2. Advantages of Spring MVC

(1) Can support a variety of view technologies, not just JSP;

(2) Integration with Spring framework (such as IoC container, AOP, etc.);

(3) clear role allocation: front-end controller (dispatcherServlet), request to processor mapping (handlerMapping), processor adapter (HandlerAdapter), ViewResolver (ViewResolver).

(4) Support the mapping strategy of various requested resources.

Core components

What are the main components of Spring MVC?

(1) Front-end controller DispatcherServlet (no programmer development required)

Function: receive request and response results, equivalent to a forwarder, with DispatcherServlet to reduce the coupling degree between other components.

(2) Processor mapping HandlerMapping (no programmer development required)

Finds the Handler based on the requested URL

(3) HandlerAdapter

Note: When writing a Handler, follow the rules specified by the HandlerAdapter so that the adapter HandlerAdapter can properly execute the Handler.

(4) Processor Handler (programmer development required)

(5) ViewResolver (no programmer development required)

Function: Parse a view into a real view according to its logical name

(6) View View (need programmer to develop JSP)

View is an interface whose implementation classes support different View types (JSP, Freemarker, PDF, etc.)

4. What is DispatcherServlet?

Spring’s MVC framework is designed around DispatcherServlet, which handles all HTTP requests and responses.

5. What is the Spring MVC framework controller?

A controller provides a behavior to access an application, which is typically implemented through a service interface. The controller parses user input and transforms it into a model that the view presents to the user. Spring implements a control layer in a very abstract way, allowing users to create controllers for multiple purposes.

Is the controller of Spring MVC singleton? If so, what is the problem and how to solve it?

A: It is a singleton mode, so there are thread safety issues when multi-threaded access, do not use synchronization, will affect performance, the solution is to write fields in the controller.

Three. Working principle

7. Describe the Spring MVC workflow? Describe the workflow of DispatcherServlet?

(1) The user sends the request to the front-end controller DispatcherServlet;

(2) After receiving the request, the DispatcherServlet invokes the HandlerMapping processor mapper to request to obtain the Handle;

(3) The processor mapper finds the specific processor according to the request URL, generates the processor object and the processor interceptor (if any) and returns them to the DispatcherServlet;

(4) DispatcherServlet calls HandlerAdapter processor adapter;

(5) The HandlerAdapter ADAPTS to call the specific Handler (Handler, also called the back-end controller);

(6) The Handler returns ModelAndView after execution;

(7) HandlerAdapter returns the Handler execution result ModelAndView to DispatcherServlet;

(8) DispatcherServlet sends ModelAndView to ViewResolver view parser for parsing;

(9) The ViewResolver returns the concrete View after parsing;

(10) DispatcherServlet renders the View (that is, the model data is filled into the View)

(11) DispatcherServlet responds to users.

4. The MVC framework

8. What is MVC? What are the benefits of the MVC design pattern

5. Common notes

9. What is the principle of annotations?

  • Annotations are essentially a special interface that inherits annotations, implemented by dynamic proxy classes generated by the Java runtime. When we get annotations through reflection, we return a dynamic proxy object generated by the Java runtime. Through a proxy object call custom injection solution method, will eventually call AnnotationInvocationHandler invoke method. This method indexes the corresponding value from the Map memberValues. The source of memberValues is the Java constant pool.

What are common Spring MVC annotations?

  • RequestMapping: annotation used to handle requested URL mapping, which can be used on a class or method. For a class, that means that all methods in the class that respond to requests have that address as the parent path.
  • @RequestBody: Annotation implementation receives JSON data from HTTP requests and converts json to Java objects.
  • ResponseBody: The annotation implementation converts the object returned by the Conreoller method into a JSON object response to the client.
  • Conntroller: controller annotations that represent the presentation layer and cannot be replaced by other annotations

11. What is the general annotation of the controller in SpingMvc? Is there any other annotation that can replace it?

  • A: The @Controller annotation is usually used, but the @RestController annotation is also used. The @restController annotation is equivalent to @responseBody + @Controller, indicating that it is the presentation layer

12. What does the @Controller annotation do?

13, What does @requestMapping do?

14, What is the @responseBody annotation for?

  • Function: This annotation is used to write an object returned by Controller’s methods to the body data section of the Response object after converting it to the specified format via the appropriate HttpMessageConverter.
  • When to use: when the data returned is not HTML tag pages, but some other format of data (such as JSON, XML, etc.);

The difference between @pathVariable and @requestParam

  • @pathVariable = @requestMapping (value = “/page/{id}”, method = requestmethod.get)
  • RequestParam is used to get static URL requests into spring annotations for action.

6. Other

16, Spring MVC and Struts2 differences:

How does Spring MVC set up redirection and forwarding?

How do Spring MVC and AJAX call each other?

19, How to solve the POST request Chinese garble problem, and how to deal with GET?

Spring MVC exception handling?

  • A: You can throw exceptions to the Spring framework, which handles them; We just need to configure a simple exception handler and add a view page to the exception handler.

21. What can I do if I want to intercept methods submitted by GET

  • A: You can add method= requestMethod.get to @requestMapping

22. How do I get a Request or Session from a method?

  • A: Declare request directly in a method parameter, and Spring MVC automatically passes in the Request object.

23. If you want to get an argument passed from the foreground in an intercepting method, how do you get it?

  • A: Declare the parameter in the parameter, but only with the same name as the passed parameter.

24, If the foreground has a lot of parameters passed in, and these parameters are an object, so how to quickly get the object?

  • A: Declare the object directly in a method, and Spring MVC automatically assigns properties to the object.

What is the return value of a function in Spring MVC?

  • A: Return values can have many types, including String, ModelAndView. The ModelAndView class merges views and data together, but strings are usually better

26. What object does Spring MVC use to pass data from the background to the foreground?

  • A: With ModelMap objects, you can call the PUT method in this object, add the object to it, and the foreground can get it through the EL expression.

27. How to put ModelMap data into Session?

  • A: You can add the @sessionAttributes annotation on top of the class, which contains a string that is the key to put into the session.

28. What is the interceptor in Spring MVC?

  • There are two ways to write, one is to implement the HandlerInterceptor interface, the other is to inherit the adapter class, and then in the interface method, implement the processing logic; Then configure the interceptor in the Spring MVC configuration file:
<! < MVC :interceptors> <! - configure an interceptor Bean The default is for all requests to intercept - > < bean id = "myInterceptor" class = "com. ZWP. Action. MyHandlerInterceptor" > < / bean > <! < MVC :interceptor> < MVC :mapping path="/ modelmap.do "/ > <bean class="com.zwp.action.MyHandlerInterceptorAdapter" /> </mvc:interceptor> </mvc:interceptors>Copy the code

29. WebApplicationContext:

  • WebApplicationContext inherits ApplicationContext and adds some features unique to WEB applications. It is different from ordinary ApplicationContext in that it can handle topics and find the associated servlets.

29 Spring Classic interview questions 【 Attached answer analysis 】

The last

Space is limited, other content will not be shown here one by one, sorting is not easy, welcome everyone to exchange, like xiaobian to share the article remember to pay attention to me like yo, thank you for your support!