In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
[preface]
A few days ago, we studied the notes in Java together. Today, let's learn the Springboot notes and get a little familiar with the framework from the composition principle of the framework.
[Spring]
When it comes to SpringBoot, you have to know what Spring is. Because SpringBoot is a framework that simplifies Spring development.
A, Spring is a lightweight control inversion (IoC) and aspect-oriented (AOP) container framework
Control inversion-Spring promotes loose coupling through a technique called control inversion (IoC)
Aspect-oriented-Spring provides rich support for aspect-oriented programming
B, Web module of Spring
The Web context module is based on the application context module and provides a context suitable for Web applications. In addition, this module also provides some service-oriented support. For example: multipart request for file upload, which also provides integration of Spring and other Web frameworks, such as Struts and WebWork.
C, MVC framework of Spring
Spring provides a full-featured MVC framework for building Web applications. Although Spring can be easily integrated with other MVC frameworks, such as Struts, Spring's MVC framework uses IoC to provide complete separation of control logic and business objects.
It also allows you to declaratively bind request parameters to your business objects. In addition, Spring's MVC framework can take advantage of any other Spring services, such as internationalization information and validation.
********
[analysis of the principle of Springmvc architecture]
Step 1: initiate a request to the front-end controller (DispatcherServlet)
Step 2: the front controller requests HandlerMapping lookup Handler can be found according to xml configuration and comments
Step 3: processor mapper HandlerMapping returns Handler to the front-end controller
Step 4: the front-end controller calls the processor adapter to execute the Handler
Step 5: processor adapter to execute Handler
Step 6: Handler execution completes and returns ModelAndView to the adapter
Step 7: the processor adapter returns ModelAndView to the front controller
ModelAndView is an underlying object of the springmvc framework, including Model and view
Step 8: the front-end controller requests the view parser to parse the view
Parse to a real view (jsp) based on the logical view name
Step 9: the view parser returns View to the front controller
Step 10: front-end controller for view rendering
View rendering populates the model data (in ModelAndView objects) into the request field
Step 11: the front controller responds to the result to the user
Components:
①, front-end controller DispatcherServlet (does not need programmer development) function to receive requests, response results, equivalent to transponders, CPU. With DispatcherServlet, the coupling between other components is reduced.
②, processor mapper HandlerMapping (no programmer development is required) function: to find Handler based on the requested url
3. Processor adapter HandlerAdapter function: execute Handler according to specific rules (rules required by HandlerAdapter)
③, processor Handler (need programmer development) Note: when writing Handler, follow the requirements of HandlerAdapter, so that the adapter can execute Handler correctly.
④, view parser View resolver (does not require programmer development) function: view parsing, according to the logical view name parsing into a real view (view)
⑤, View View (programmers are required to develop jsp) View is an interface that implements classes that support different View types (jsp, freemarker, pdf... )
*******
[common notes on SpringMVC]
@ Controller
Responsible for registering a bean into the spring context
@ RequestMapping
Comments specify which URL requests can be processed for the controller
@ RequestBody
This annotation is used to read the body part of the data requested by Request, parse it using the HttpMessageConverter configured by default, bind the corresponding data to the object to be returned, and then bind the object data returned by HttpMessageConverter to the parameters of the method in controller
@ ResponseBody
This annotation is used to write the object returned by the Controller method to the body data area of the Response object after it is converted to the specified format through the appropriate HttpMessageConverter.
@ ModelAttribute
Use @ ModelAttribute annotation on method definition: Spring MVC calls methods marked @ ModelAttribute at the method level one by one before calling the target processing method.
Use @ ModelAttribute annotation before the input parameter of the method: you can get the object from the implied model data from the implied object, bind the request parameter-to the object, and then pass in the input parameter to add the method input parameter to the model
@ RequestParam
Use @ RequestParam at the input of the processing method to pass the request parameters to the request method
@ PathVariable
Bind URL placeholders to input parameters
@ ExceptionHandler
Comment on the method, which will be executed when an exception occurs
@ ControllerAdvice
Make a Contoller a global exception handling class, and the methods annotated with the @ ExceptionHandler method in the class can handle all exceptions that occur in Controller
[comparison between SpringMVC and Struts2]
A, spring mvc and struts2 have different loading mechanisms: the entry of spring mvc is servlet, while struts2 is filter (see the difference between servlet and filter at the end of this article)
B, Struts2 framework is class-level interception
C and SpringMVC are method-level interceptions.
[JPA Note]
Entity: indicates that this is an entity class.
MappedSuperClass: used to identify the entity that is the parent class. The attribute subclasses of the parent class can inherit.
NoRepositoryBean: a repository that is generally used as a parent class. With this annotation, spring will not instantiate the repository.
Column: if the field name is the same as the column name, it can be omitted.
Id: indicates that the property is the primary key.
JoinColumn (name= "loginId"): one-to-one: a foreign key in this table that points to another table. One-to-many: another table points to the foreign key of this table.
@ OneToOne, @ OneToMany, @ ManyToOne: correspond to one-to-one, one-to-many, many-to-one in the hibernate configuration file.
[global exception comments]
@ ControllerAdvice: contains @ Component. Can be scanned. Handle exceptions uniformly.
ExceptionHandler (Exception.class): used on a method to indicate that the following method is executed when this exception is encountered.
[specific configuration resolution and usage environment notes in the project]
@ MappedSuperclass:
1.@MappedSuperclass annotations are used on the parent class to identify the parent class
The class identified by 2.@MappedSuperclass indicates that it cannot be mapped to a database table because it is not a complete entity class, but its attributes can be mapped in the database table to which its subclasses are matched.
Classes identified by 3.@MappedSuperclass can no longer have @ Entity or @ Table annotations
@ Column:
1. You need to use the @ Column annotation when the attribute of the entity is different from the column of the database table it maps to, which is usually preceded by the attribute declaration statement of the entity and can also be used with the @ Id annotation.
A common property of 2.@Column annotations is name, which is used to set the column names of mapped database tables. In addition, the dimension also contains a number of other attributes, such as: unique, nullable, length, precision and so on.
[execute persistence method, callback function executed according to occurrence time]
@ javax.persistence.PostLoad: after loading.
@ javax.persistence.PrePersist: before persistence.
@ javax.persistence.PostPersist: after persistence.
@ javax.persistence.PreUpdate: before update.
@ javax.persistence.PostUpdate: after update.
@ javax.persistence.PreRemove: before deletion.
@ javax.persistence.PostRemove: after deletion.
[database annotations]
1) increase
The @ PrePersist and @ PostPersist events occur during the insertion of entity objects into the database:
The @ PrePersist event occurs immediately after the persist () method is called, and the data has not actually been inserted into the database.
The @ PostPersist event occurs after the data has been inserted into the database.
2) delete
The triggers of @ PreRemove and @ PostRemove events are caused by deleting entities:
The @ PreRemove event is triggered before the entity is deleted from the database, that is, when the remove () method is called, and the data has not actually been deleted from the database.
The @ PostRemove event is triggered after the entity is deleted from the database.
3) change
The @ PreUpdate and @ PostUpdate events are triggered by the update entity:
The @ PreUpdate event is triggered before the state of the entity is synchronized to the database, when the data has not actually been updated to the database.
The @ PostUpdate event is triggered after the state of the entity is synchronized to the database, and synchronization occurs when the transaction commits.
4) check
The @ PostLoad event is triggered in the following situations:
After executing the EntityManager.find () or getreference () method to load an entity.
After executing the JPQL query.
After the EntityManager.refresh () method is called.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.