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--
[SpringMVC Introduction]
Spring MVC is a successor to SpringFrameWork and has been integrated into Spring Web Flow. The Spring Framework provides full-featured MVC modules for building Web applications. Use Spring pluggable MVC architecture, so that when using Spring for WEB development, you can choose to use Spring MVC framework or integrate other MVC development frameworks, such as Struts1(now generally not used), Struts 2(generally used by old projects), etc.
Spring MVC
@Controller
Responsible for registering a bean into the spring context
@RequestMapping
Annotations specify which URL requests the controller can process
@RequestBody
This annotation is used to read the data of the body part of the Request request, parse it using the HttpMessageConverter configured by default, and then 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 the controller.
@ResponseBody
This annotation is used to convert the object returned by the Controller method into the specified format by using the appropriate HttpMessageConverter and write it to the body data area of the Response object.
@ModelAttribute
@ModelAttribute annotation on method definitions: Spring MVC calls methods labeled @ModelAttribute at the method level one by one before calling target processing methods
Use @ModelAttribute annotation before method parameters: You can get objects from implicit model data, then bind request parameter-to objects, and then pass in method parameters to add objects to models
@RequestParam
Request parameters can be passed to the request method using @RequestParam at the processing method entry parameter
@PathVariable
Binding URL Placeholders to Input Parameters
@ExceptionHandler
Annotate to the method, which will be executed when an exception occurs
@ControllerAdvice
Make a Contoller a global exception handler class, where methods annotated with @ExceptionHandler methods handle all exceptions that occur with Controller.
SpringMVC vs Struts2
A. The loading mechanism of spring mvc and struts2 is different: 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 a class-level interception
C. SpringMVC is a method-level interception
[JPA Note]
@Entity: Indicates that this is an entity class.
@MappedSuperClass: Used on entities that are determined to be parent classes. Subclasses can inherit attributes from their parent class.
@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 attribute 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 a foreign key of this table.
@OneToOne,@OneToMany,@ManyToOne: Corresponding to one-to-one, one-to-many, many-to-one in hibernate configuration file.
[Global Exception Comments]
@ControllerAdvice: Contains @Component. can be scanned. Unified handling of exceptions.
@ExceptionHandler (Exception.class): Used above a method to indicate that this exception is encountered and the following method is executed.
[Detailed configuration analysis and usage environment comments in the project]
@MappedSuperclass:
1.@ The MappedSuperclass annotation is used above the parent class to identify the parent class.
2.@ The class identified by MappedSuperclass indicates that it cannot be mapped to a database table because it is not a complete entity class, but it has attributes that can be mapped to database tables for which it is a subclass.
3.@ Classes identified by MappedSuperclass cannot have @Entity or @Table annotations
@Column:
1. The @Column annotation is required when an entity's attribute does not have the same name as the column of the database table to which it maps. This attribute is usually placed before the entity's attribute declaration statement and can also be used with the @Id annotation.
2.@ The common attribute of Column annotation is name, which is used to set the column name of the mapping database table. In addition, the label contains several other attributes, such as unique, nullable, length, precision, and so on.
[Executing persistent methods, callback functions executed by 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: Remove before.
@javax.persistence.PostRemove: After deletion.
[Database Notes]
1) Increase
@PrePersist and @PostPersist events occur during the insertion of entity objects into the database:
The @PrePersist event occurs immediately after calling the persist() method, before the data has actually been inserted into the database.
The @PostPersist event occurs after the data has been inserted into the database.
2) Delete
Triggers for @PreRemove and @PostRemove events are caused by deleting entities:
The @PreRemove event is triggered before an entity is deleted from the database, i.e., when the remove() method is called, before the data has actually been deleted from the database.
The @PostRemove event is triggered when an entity is removed from the database.
3) Change
Triggers for @PreUpdate and @PostUpdate events are caused by update entities:
The @PreUpdate event is triggered before the entity's state is synchronized to the database, when the data has not actually been updated to the database.
The @PostUpdate event is triggered after the entity's state is synchronized to the database, which occurs when the transaction commits.
4) Check
The @PostLoad event is triggered when:
After executing EntityManager.find() or getreference() methods to load an entity.
After executing JPQL query.
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.