Spring MVC interview Finishing

Source: Internet
Author: User

  1. Spring MVC Execution Process

    1. Client's request submitted to Dispatcherservlet

    2. Dispatcherservlet query one or more handlermapping, find the requested controller

    3. Dispatcherservlet submits the request to the controller and returns Modelandview when the controller call is complete

    4. Dispatcherservlet queries one or more corresponding front-end controllers to pass Modelandview to the specified front-end controller

    5. Returns the rendered view to the client

  2. The controller for SPRINGMVC is a singleton, as far as possible not to set properties, but in the method

  3. @RequestMapping annotations are used above the class to represent the parent path of the class method

  4. The main difference between SPRINGMVC and Struts2

    • SPRINGMVC's front controller is a servlet and struts is the filter

    • The SPRINGMVC controller is a singleton, while the STRUTS2 action is a multi-instance

    • SPRINGMVC is by parsing the contents of the request into formal parameters, encapsulating the corresponding and the pages as Modelandview objects, and struts2 using the value stack to store the request and the corresponding

  5. SPRINGMVC's Interceptor

    • Class implements interface Handlerinterceptor, implementation methods, methods corresponding to the method before execution, after the page rendering

    • Then configure the interceptor in the configuration file

    • When multiple interceptors are executed together, the Prehandler is executed in the configured order, and the remaining two interceptors will be executed when Prehandler returns to true.

    • Posthandler and aftercompletion are called in reverse order of configuration

  6. Json

    • @ResponseBody Output JSON

    • @requestbody Accept JSON conversion to Pojo

  7. Uploading files

    • Front-end Rules

    • Configuring multimedia in a configuration file

    • Use Multipartfile to accept files in controller

  8. Three major components and cores

    • Core: Dispatcherservlet (Front Controller)

    • Three main components:

    • Viewresolver: View resolver ()

    • Handlermapping: Processor Mapper Component (find handler for pathname)

    • Handleradapter: Processor Adapter Component (execution handler)

  9. The main annotations

    • Access path to the @requestmapping ()//method Value,method=post limit the request to Get/post

    • @Controller

    • @ResponseBody

    • @RequestBody

    • @

  10. Interception rules

    • /* intercept all, including JSP

    • /interception of resources other than JSP

  11. The return value of the controller

    • Modelandview: Returning views and parameters

    • Model: Pass model in method, return value to string, direct return view

    • Void: Nothing is reversed back

  12. Redirect and request forwarding

    • Add a keyword return ‘redirect:/item/itemlist.action‘ to the front of the pathreturn ‘forward:/item/itemlist.action‘
  13. Parameter binding

    • public ModelAndView toEdit(Integer id,HttpServletRequest request,HttpServletResponse response,HttpSession session)
  14. Exception handling

    • Inherit handlerexceptionresolver implement the corresponding method, handle the error

    • SPRINGMVC Configuration<bean class="com.lyh.exception.CustomerException"></bean>

  15. The "Type=test" string is included in the Intercept submission parameter

    • 可以在@RequestMapping注解里面加上params="type=test"
  16. Springmvc what objects are used to pass data from the background to the foreground

    • Through the Modelmap object, you can put the object inside the object with the Put method, the foreground can be obtained by El Expression
  17. How to put the data inside the Modelmap into the session

    • You can add a @sessionattributes annotation to a class that contains a string that is the key to be placed inside the session
  18. SPRINGMVC Controller is not a singleton mode, if yes, what is the problem, how to solve

    • is a singleton mode, so in multi-threaded access when the thread security issues, do not use synchronization, will affect performance, the solution is in the controller can not write segments

Spring MVC interview Finishing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.