Notes of _java finishing spring MVC

Source: Internet
Author: User
Tags map data structure

SPRINGMVC principle Explanation Address: http://www.cnblogs.com/dragonfei/p/6148625.htmlIonic2 and Angularjs2 and the Angularjs and NoSQL rookie tutorials are made with HTTPS for mobile phones://www.bilibili.com/video/av8614724/index_10.html is ionic2 Open class address .freecmsdedecms Wind Network, database table structure Dedecms simple station filter and interceptor the difference between filter is based on function callback, and interceptor is based on Java reflection. The filter relies on the servlet container, and interceptor does not depend on the servlet container. Filter works on almost all requests, and interceptor only works on action requests. Interceptor can access the context of the action, the object in the value stack, and filter cannot.  (Struts framework) in the life cycle of the action, interceptor can be called multiple times, and filter can only be called once in the container initialization Springmvc interceptor, there are 2 ways to implement Handlerinterceptor interface Rewrite the method inside, the most important thing isBooleanprehandler inherit handlerinterceptoradapter, rewriteBooleanPrehandler (recommended)return trueReleasereturn falseStop executing admin-Servlet.xml is a background controller, Web. XML is the page controller cookies can see the session generated UUID same browser session, to login to multiple accounts to open a different browser MVC framework? Spring<--ORM Framework SPRINGMVC mybaties servlet JDBC struts hibernate set slow After saving, paged query does not add usecache when cached=false"indicates canceling the cache* A representative and directory, * *two delegates n directory sesion when Tomcat is saved for about 30 minutes, the development session stored in the memory EJB Enterprise is the difference between the map collection Pojo and the entity class: The entity class implements the Serializable interface, and the database field corresponds to the Po Jo is a tool class, unrelated to the database model and view do not interact directly with data swift playground a simple programming language for parameter injection: Set method constructor Interface injection servlet only instantiates once, when used Load Uuid.randomuuid () computer generated non-duplicated digital Java picture Verification code in JSP can be used in ternary operation sex==0?" male": "female" convention is greater than configuration refers to, in the page first write the virtual path and related parameters, and then the controller in the parameter to the page consistent with the parameters in the controller: @param ("Teaid")intTeaid, @param ("Teaname") concatenation of String functions in string Teanameexcel:=b3& "=" & "#{" &B3& "}" & ","Ajax-provided page validation loses focus before validating data-bv-trigger= "Blur"RESTful Semantic address parameter Kindeditor file upload, picture, rich text box is also file uploadThrow NewRuntimeException ("Bulk upload of student information failed"); Java Countdown jump page document.getElementById (' href '). href found address MD5 encrypt 32-bit MD5 add salt transaction characteristics: atomicity, consistency, isolation, Persistent poi File Upload Artdialog is the Bootstrap Art dialog mapper method is not mapped out when the project will be error reactnativeand Ionic are professional to do mobile app Angularjsparam.marjorid last query passed past the parameter loop is selected in the option to restore the date plug-in Datetimepickerbootstrap Validate Verifying Data-bv-trigger="Blur" after the mouse moved to verify the style JSP page code extraction: For a period of continuous page code will be reused, the JS and CSS extracted separately to a separate JSP file on the original page through<jsp:include page= "common/common_js.jsp" ></jsp:include>when referencing spring MVC injection, the date will be an error, to be processed in the entity class @DateTimeFormat (Pattern= "Yyyy-mm-dd") Dynamic injection: @Autowired//Spring-implemented dynamic agents@Resource (name= "Classesmapper")//Java Framework implements dynamic proxyBackground Service Interface extraction: Packaging public mapper Operation Insert,update,findbyid, Search () (commonmapper) has pagination on the operation without paging,intSearchpagecount () (Commonpagemapper) encapsulates a public service that does not have paging operations Insert,update,findbyid, search () (Commonservice) is paged, Based on an operation without paging,intSearchpagecount () (Commonpageservice) encapsulates the public Service.impl operation without paging Insert,update,findbyid, search () To establish a Commonserviceimpl, call the Commonmapper class, you must give a set method, The subclass to assign a value to the Commonpageserviceimpl inheritance Commonserviceimpl call Commonpagemapper must give a set method, so that the subclass to assign the database and the entity class column name is not the same, Query statement to be added as processing paging public interface inherit public interface bootstrap floating CSS with pull in the right-Righta label Submission Form:<a href= ' javascript:document.getElementById (' Form1 '). Submit (); ' ></a>Spring MVC separates the roles of controllers, model objects, filters, and handler objects, which makes them easier to customize MVC is a design pattern, three-tier architecture is a thought JSP nature is servletspring MVC: contractual programming, conventions larger than configuration, The first name to write dead concrete steps:1. First the user sends the request--Dispatcherservlet, the front-end controller receives the request and does not process it, but delegates to the other parser for processing, as a unified access point, the global process control;2, dispatcherservlet-->handlermapping,handlermapping will map the request to a Handlerexecutionchain object containing a Handler processor (page Controller) object, multiple Handlerinterceptor Interceptor) object, through this policy mode, it is easy to add a new mapping strategy;3, dispatcherservlet-->The Handleradapter,handleradapter will package the processor as an adapter to support multiple types of processors, the adapter design mode application, which makes it easy to support many types of processors;4, Handleradapter-->Processor function Processing method call, Handleradapter will be based on the results of the adaptation to call the real processor function processing method, complete the function processing, and return a Modelandview object (including model data, logical view name);5, Modelandview logical View name---Viewresolver, Viewresolver will parse the logical view name into a specific view, through this strategy mode, it is easy to change other view technology;6, View-->rendering, the view is rendered based on the model data passed in, the model is actually a MAP data structure, so it is easy to support other view technology;7, return control to Dispatcherservlet, return the response by Dispatcherservlet to the user, to the end of this process. Core Development Steps1, Dispatcherservlet the deployment description in Web. XML, thus intercepting the request to Spring Web MVC2, handlermapping configuration to map the request to the processor3, handleradapter configuration to support multiple types of processors4, viewresolver configuration, which resolves the logical view name to the specific view technology5, Processor (page Controller) configuration for functional processing configuration Spring MVC and MyBatis best not to use spring MVC alone-->spring <--MyBatis1), resource below to establish a file named Applicationcontext.xml (can be changed, the default is called this)2), do the following configuration in this2.1), sweep package (business logic package, data access package)2.2), Declaration support annotation Method2.3), the operation of the data connection pool (database, driver, user name, password ...) 2.4), create Sqlsessionfactory2.5), configure transaction management2.6), using spring AOP (dynamic proxy) to set which methods to do what (read-only can be submitted)3), configure some common settings for mybatis, such as debug print out SQL, map file under which package4), and finally, in Web. XML, start the newly configured Applicationcontext.xml1, when the user sends the Web request through the browser, first receives the application server, for example Tomcat, the application server through the protocol parsing and so on a series of actions, the request object HttpServletRequest to Dispatcherservlet, Dispatcherservlet is the core entrance to spring MVC. 2, Dispatcherservlet will set some request-related properties in the Doservice method after receiving request requests, such as ApplicationContext, support for internationalization localresolver, etc. The request is then referred to the requesting processing adapter3, Spring in the initialization of the applicationcontext phase will be the request URI and the request processor to a mapping, during the run time by the request processing adapter Handleradapter through the requester object to find the corresponding processor The handler in Handlermethod,spring MVC is the object type, which is actually a @reqquestmapping method on the controller, [emailprotected]4, Handler handles the request, that is, the Modelandview view object is returned after the corresponding business method logic is called, and then the Applyposthandle method of Handlerexecutionchain is called to process the View object5, Spring MVC uses the view resolver to parse the Modelandview object, and then generates the corresponding page by Dispatcherservlet, which writes the response back to the client, which basically completes the processing of the entire request.1, when the initialization of SPRINGMVC is complete, it enters the second stage of the servlet "Service" period, when the browser sends a request to the server, the servlet container starts a thread, passes the service () method to go to Doget or dopost to process the request. 2at this point, SPRINGMVC has established a sub-context in which various programming elements are stored through dependency injection. Struts2 takes an event mechanism that is completely isolated and decoupled from the Web container. such as the action object, the result object, and the Interceptor object are all programming elements that are completely detached from the servlet container. Struts2 the data flow and event processing are completely stripped out, after reading the data from the HTTP request, the following event processing process relies on only that data and is completely unaware of the existence of a web environment. SPRINGMVC, whether Handlermapping objects, Handleradapter objects, or view objects, the methods defined by these core interfaces, Both the HttpServletRequest and HttpServletResponse objects appear directly as arguments to the method. This means that the architect of the framework binds the SPRINGMVC framework and the container directly together. Or, the entire SPRINGMVC framework is designed with the servlet container elements in it. 3, Dispatcherservlet as a standard servlet, then when a request comes in, we can follow the servlet execution process to analyze how he handled the request. For SPRINGMVC's template design pattern, we often go to the parent class to find the method we need. The following is the beginning of the Dispatcherservlet, to analyze a request process the spring MVC request processing process starts from the configuration of the servlet in Web. XML, based on the URL that the servlet intercepts-Parttern, to make a request to forward a spring workflow description1the user sends a request to the server and the request is captured by the spring front-end control Servelt Dispatcherservlet;2. Dispatcherservlet parses the request URL to get the request Resource Identifier (URI).      Then, according to the URI, call handlermapping to get all the related objects of the handler configuration (including the handler object and the interceptor corresponding to the handler object), and finally return as a Handlerexecutionchain object; 3. Dispatcherservlet according to the obtained handler, choose a suitable handleradapter. (Note: If Handleradapter is successfully obtained, the Interceptor Prehandler (...) will start executing. method)4. Extract the model data from the request, populate the handler entry, and start executing the handler (Controller). In the process of populating the handler, depending on your configuration, spring will do some extra work for you: Httpmessageconveter: Converts the request message (such as JSON, XML, and so on) to an object, converting the object to the specified response Information Data transformation: Yes, Request a message for data conversion. such as string conversion to Integer, double, and other data is radical: The request message is formatted data. Data validation such as converting a string to a formatted number or a formatted date: Verifying the validity of the data (length, format, etc.), and verifying that the result is stored in Bindingresult or error5. Handler returns a Modelandview object to Dispatcherservlet when execution is complete;6. Based on the returned Modelandview, select a suitable viewresolver (must be viewresolver already registered in the spring container) to return to Dispatcherservlet;7. Viewresolver combining model and view to render the view8. Returns the rendered result to the client.     Why does spring use only one servlet (Dispatcherservlet) to handle all requests? See the Java EE design pattern in detail-front-end control mode Why does spring use handlermapping and handleradapter to handle handler?conforms to the single-object-oriented principle of responsibility, code architecture is clear, easy to maintain, and most importantly, code reusability is high. such as handleradapter may be used to handle a variety of handler1when Dispatcherservlet receives a request, he first finds the appropriate handler to process the request. Dispatcherservlet maps each request to a handler through one or more handler mappings. The handler mapping is configured in the context of the Web application and is the bean that implements the Handlermapping interface. It is responsible for returning an appropriate handler (that is, controller) for the request. Handler mappings typically map requests to handlers (controllers) based on the URL of the request. 2once the Dispatcherservlet chooses the appropriate controller, it calls the controller to process the request. 3when the controller finishes processing the request, it returns the model and the view name (sometimes the View object) to Dispatcherservlet. The model contains the properties that the controller will pass to the view for display. If the name of the view is returned, it is parsed into the view object and then rendered. The basic class for binding models and views is Modelandview4when Dispatcherservlet receives the model and view name, it resolves the logical view name into a View object and renders it. Dispatcherservlet parses a view from one or more view parsers. The view resolver is configured in the context of the Web application and is the bean that implements the Viewresolver interface. Its task is to return the attempted object based on the logical view name. 5once Dispatcherservlet views name resolution is called an attempted object, it renders the view object and passes the model returned by the controller. The task of the view is to present the model properties to the user. How does Dispatcherservlet map to the controller after receiving the request? In spring MVC, a Web request is mapped to a controller by one or more handler mapping beans declared in the context of the Web application (the bean that absorbs the handlermapping interface). Spring MVC provides several handlermapping implementations:1. Beannameurlhandlermapping (by default), he maps requests to handlers based on the URL pattern specified in the controller bean name. eg. <bean name= "/welcome.htm"class= "Com.kevin.controller.WelcomeController" >...</bean>When you access http://******/welcome.htm This URL, Dispatcherservlet found Welcomecontroller through beannameurlhandlermapping mapping. 2. Controllerclassnamehandlermapping, which is a map request by controller class name. 3. simpleurlhandlermapping, map the request with a custom mapping definition. Controller interface: is the basic interface for all controller classes in spring MVC. By implementing this interface, you can create your own controller. In the HandleRequest () method, you can handle Web requests arbitrarily. Abstractcontroller: If you want the controller to have some basic features, such as filtering supported HTTP methods (Get,post and head), and generating the cache in the HTTP response-control head and so on, you can let it extend the Abstractcontroller class. Parameterizableviewcontroller: Used to create a controller with a parameterized view. Simpleformcontroller: It supports the concept of a Command object (commandName) and can bind the value of a form field to an attribute of the same name on the command object. Abstractwizardformcontroller: A basic task is defined for the processing of a wizard form. The wizard form has multiple single pages, so you must define multiple page views for the wizard form Controller. The controller can then manage the form's status across all of these form pages. The wizard form will have multiple actions, unlike Simpleformcontroller with only a single commit action. The Abstractwizardformcontroller determines the user's action based on the special request parameters, usually by specifying the action with the name of the Submit button. _finished: Complete the wizard form. _cancel: Cancels the wizard form. _TARGETX: Enter the target page, where x is the index of the page starting at 0. Multiactioncontroller: Allows you to group multiple related actions into a single controller. The analysis of several common viewresolver:1. Internalresourceviewresolver: Resolves the view based on the URL. Each view name is mapped to a URL by adding the prefix and suffix methods. 2. Xmlviewresolver: Parses the view from the XML configuration file. Declare the view as a spring bean and parse it by their bean name. 3. Resourcebundleviewresolver: Parses the view from the ResourceBundle. 4. To parse the view with multiple view parsers, it is important to note that you need to configure the resolution priority for the view parser that you configure. <property name= "order" value= "0"/> value is lower, the higher the priority.

Notes of _java finishing spring MVC

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.