[Questions] SpringMVC surface portions face questions

SpringMVC face questions

What is SpringMVC? Brief introduction of your understanding of SpringMVC?

SpringMVC is a Java-based implementation of the request for driving the MVC design pattern lightweight Web framework type, separated by Model, View, Controller, functions to decouple the Web layer, the complex Web application into logical sections clearly, simplify development, reduce errors, to facilitate engagement between the inner group of developers

SpringMVC process

  1. The user sends a request to the front-end controller DisparcherServler
  2. DisparcherServlet receipt of the request, calling HandlerMapping processor mapper, Request Handle
  3. The processor mapper URL locate specific processor upon request, generates an object and a processor blocker (if generated) together back to DisparcherServlet
  4. DispartcherServlet call HandlerAdapter processor adapter
  5. HandlerAdapter adapter calls through specific processor (Handler)
  6. Handler perform complete return ModelAndView
  7. HandlerAdapter the results of the Model ModelAndView returned to DispartcherServlet
  8. The DispartcherServlet ModelAndView pass ViewResolver view parser parses
  9. Analytical ViewAResokver returned backward particular View '
  10. View DispatcherServlet to render the view (a view model soon filled to view)
  11. DispartcherServlet the user

 

SpringMVC advantage

  1. Technology can support a variety of views, but not limited to JSP
  2. Integration with Spring Framework (e.g. IOC container .AOP etc.) '
  3. Clear role assignment: front-end controller (DispartcherServlet), maps the request to the processor (handlerMapping), the adapter processor (HandlerAdapter), view resolver (ViewResolver).
  4. It supports a variety of resource mapping policy request

 

SpringMVC major components

  1. The front controller DispartcherSerlver (not require programmers to develop)

Action: receiving a request, the corresponding results, corresponding to the transponder, with DisparcherServlet reduces the degree of coupling between the other components.

  1. Processor mapper (the HandlerMapping) (not require programmers to develop)

Role: According to the URL request to find Handler

  1. This is the method handler adapter HandlerAdpater Controller class

Note: At the time of writing Handler, according to the rules oh HandlerAdapter be required to write so that the adapter can only be true of HandlerAdapter to perform Handler

  1. Processor Controller (requires programmers to develop)
  2. View resolvers ViewResolver (does not require programmers to develop)
  3. View View (requires programmers to develop JSP)

View is an excuse, its implementation support different view types (JSP, PDF, etc.)

 

SpringMVC is how to set redirection and forwarding?

  1. Forwarding: In the return values ​​preceded by "forward", such as "forward: user.do name = method4?"
  2. Redirection: the return to the previous value plus "redirect", such as "redirect: http: //www.baidu.com

 

SpringMVC is how AJAX and call each other?

Jackson by the Java framework can be converted directly to the inside of the object can be identified by JS Json objects, specifically the following steps.

  1. Join Jackson.jar
  2. Json configuration mapping in the configuration file
  3. AJAX receiving inside method can directly return object, list, etc., but before the method to add comment @ResponseBody

 

Spring MVC Exception Handling

Can throw the Spring Framework, Spring Framework to deal with: we only need to configure a simple exception handling, add a page in the exception handler can

 

SpringMVC controller is not a singleton? If so, what is the problem, how to solve?

It is a singleton. So when multithreaded access, there is a thread safety problem, do not use synchronization, it will affect the performance of the solution is not written in the controller inside the field

 

SpringMVC commonly used annotation what?

@RequestMapping: Url relieve mapping for processing a request, the class or method can be used. For the class is the representation of all the corresponding request class are changed to the address as a parent path

@RequestBody: receiving annotations to achieve the Http request json data, converts a Java object json

@ResponseBody: Notes achieve Conreoller method returns a json object into an object corresponding to the customer.

 

SpringMVC annotation controller which is generally used, there is no other alternative to misinterpretation?

@Controller general use annotations, you can use @ RestController, @ RestController annotation is equivalent to @ ResponsBody + @ Controller, the presentation layer representation is, in addition, generally do not comment other substitute

 

If intercept request, I would like to get advice available method to submit, how to configure?

Can add method = RequestMethod.GET in @RequestMapping notes inside.

 

In the process of how to get there Request or Session

Request parameters in the form of a direct statement of the method, SpringMVC will automatically pass the request object

 

If you want to get from the front desk parameters passed in a method to intercept it, how to get?

Ian statement directly in this parameter can be in the form of parameters, but the names and parameters must pass over the same.

 

If the front desk there are a lot of songs passed parameters, and these parameters is an object, then how to quickly get this object?

This object is declared directly in the process, SpringMVC will automatically assign attributes to this object inside

 

SpringMVC what the return value of the function is?

The return value can be many types, there String, ModelAndView, ModelAndView the view class and data are combined together, it is generally better to use String

 

SpringMVC annotations principle?

Nature annotation is inherited special interface Annotation, the specific implementation class is generated by the Java run-time dynamic proxy class, getting notes by reflecting our return is to generate Java runtime dynamic proxy object, call custom menmberValues ​​through a proxy object Map this index corresponding value, and is the source of memberValues ​​Java constant pool.

 

Spring declarative transaction management: annotation-based way

  1. Oh eh the transaction manager in spring.xml in, DataSourceTransactionManager
  2. Open comments in a transaction in spring.xml
  3. Transactional add annotations in the corresponding service layer

Guess you like

Origin www.cnblogs.com/yanglichen/p/11599561.html