Encapsulation method for quickly establishing framework for adding, deleting, modifying and checking applications
By encapsulating the common Controller, Service and Repository parent interfaces, the Repository implementation class is dynamically generated, which solves the cumbersome and complex problems of traditional data addition, deletions, modifications and inspections of application development processes, and achieves rapid construction and efficient development.
Patent Information
- Application Number
- CN202411574450.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-06
- Publication Date
- 2025-02-25
AI Technical Summary
The traditional data addition, deletion, modification and reference application development process based on SpringMVC and SpringDataJPA is complicated and complicated, and requires repeated writing of a large number of templated duplicate code, resulting in inefficiency.
It provides a packaging method for quickly building a framework for adding, deleting, modifying and checking applications. By encapsulating the general Controller, Service, data verification logic and Repository parent interface, it dynamically generates Repository implementation classes, and supports business logic before and after data persistence.
It realizes rapid construction, deletion, modification and inspection applications, reduces duplicate code writing, improves development efficiency, and avoids complex and tedious construction processes.
Smart Images

Figure CN119512537A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of application software development, and in particular to a packaging method for quickly building a framework for adding, deleting, modifying and checking applications. Background Art
[0002] Spring refers to a set of Java development frameworks, including SpringMVC, SpringDataJPA, SpringBoot, etc. Spring provides various services, such as dependency injection, transaction management, data access abstraction, and web application development. The core of the Spring framework is Spring MVC, which is a web application framework used to create web applications.
[0003] The main features of the Spring framework are: (1) Dependency Injection (DI): Spring uses dependency injection to manage dependencies between classes, simplifying code writing. (2) Aspect-Oriented Programming (AOP): Spring provides aspect-oriented programming capabilities that allow you to separate concerns in business logic. (3) Declarative transaction management: Spring provides declarative transaction management, which makes it easier for you to manage transactions. (4) Junit integration: Spring provides a way to integrate Junit, which makes it easier for you to write unit tests. (5) Convenient integration of various excellent frameworks: Spring can easily integrate various excellent frameworks, such as MyBatis, Hibernate, etc.
[0004] Traditionally, when developing data addition, deletion, modification and query applications based on Spring MVC (a development framework for developing Web applications using Java) and Spring Data JPA (a further encapsulation of JPA interface specifications), it is necessary to create a Controller, Service, Entity, and Repository for each entity, and write the implementation logic of addition, deletion, modification and query for each entity. Every time an entity is added, it is necessary to repeat the above steps. The steps are cumbersome and complicated, and the repetitive workload is large, which wastes time and is inefficient. Summary of the invention
[0005] The present invention provides an encapsulation method for quickly building a framework for adding, deleting, modifying and checking applications to construct a framework for building adding, deleting, modifying and checking applications. Using the framework can achieve the purpose of building adding, deleting, modifying and checking applications efficiently, quickly and simply.
[0006] To achieve the above object, the technical solution of the present invention is to provide a packaging method for quickly building a framework for adding, deleting, modifying and checking applications, and its innovation lies in: specifically comprising the following steps:
[0007] S1. Encapsulate Controller: Encapsulate a general Controller to intercept all entity addition, deletion, modification and query requests;
[0008] S2. Encapsulate Service: Encapsulate a general Service that includes a general data processing flow for adding, deleting, modifying, and checking data;
[0009] S3. Data validation logic identification: define the annotation @Validator(entity,opt) to identify the data validation logic, entity is the entity name; opt is the operation to be performed on the entity;
[0010] S4. Define events to support business logic: By defining six types of events, namely, pre-addition event, post-addition event, pre-deletion event, post-deletion event, pre-modification event, and post-modification event, various business logics before and after data persistence are supported;
[0011] S5. Encapsulate the persistence operation of the Repository parent interface: Encapsulate a general Repository parent interface to perform data addition, deletion, modification and query persistence operations, and complete the encapsulation of the framework for quickly building addition, deletion, modification and query applications. The encapsulated Repository parent interface contains the general addition, deletion, modification and query data processing flow in step S2.
[0012] Furthermore, in the step S1, the add, delete, modify and query request is set to @RequestMapping(" / {entity} / {opt} / {id}"); the entity parameter is the entity name to be operated, which corresponds to the lowercase name of the entity class; the opt parameter is the operation to be performed on the entity, and the value range is: add create, delete delete, modify update, query list list, and query single data detail.
[0013] Furthermore, the id parameter is only used when deleting, modifying, or querying a single piece of data.
[0014] Furthermore, the general data processing flow of adding, deleting, modifying and checking in step S2 is specifically as follows:
[0015] (1) The data processing flow of the added data is as follows: front-end data submission, back-end data verification, pre-added logic, added data, and post-added logic;
[0016] (2) The data processing flow for deletion is as follows: front-end data submission, back-end data verification, pre-deletion logic, data deletion, and post-deletion logic;
[0017] (3) The modified data processing flow is as follows: front-end data submission, back-end data verification, pre-modification logic, data modification, and post-modification logic;
[0018] (4) The data processing flow of the query is as follows: the front end submits the request, the back end verifies the parameters, and then queries the data.
[0019] Furthermore, in the step S3, when a certain data verification fails, a ValidateException is thrown to terminate the data processing flow; in the Service, the @Validator annotation is used to find and call the corresponding data verification logic to implement the data verification process.
[0020] Furthermore, the annotations corresponding to the six types of events in step S4 are: @BeforeCreateEvent(entity), @AfterCreateEvent(entity), @BeforeDeleteEvent(entity), @AfterDeleteEvent(entity), @BeforeUpdateEvent(entity), @AfterUpdateEvent(entity); the Service searches and calls the corresponding data processing logic through the above annotations.
[0021] Furthermore, the Repository parent interface encapsulated in step S5 includes the adding of new data, deleting data, modifying data, and querying data in the general add, delete, modify, and query data processing flow in step S2.
[0022] Furthermore, the Repository parent interface encapsulated in step S5 dynamically generates a Reopsitory implementation class for each entity at runtime through ByteBuddy; the Service performs data addition, deletion, modification, query and persistence operations through the Repository parent interface.
[0023] Compared with the prior art, the present invention has the following beneficial effects:
[0024] The framework obtained by the encapsulation method of the present invention for quickly building a framework for adding, deleting, modifying and checking applications can enable developers to avoid writing a large amount of templated repetitive code when building add, delete, modify and check applications. Developers only need to focus on key points such as Entity, data verification logic, and logic before and after data persistence. The framework encapsulated by the method of the present invention is used to quickly build add, delete, modify and check applications, thereby improving the building efficiency and avoiding a complex and tedious building process. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0026] Figure 1 The present invention is a flow chart of a packaging method for quickly building a framework for adding, deleting, modifying and checking applications. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0028] Example 1
[0029] This embodiment provides a packaging method for quickly building a framework for adding, deleting, modifying and checking applications. The process is as follows: Figure 1 As shown, the specific steps include:
[0030] S1. Encapsulate Controller: Encapsulate a general Controller to intercept all entity addition, deletion, modification and query requests.
[0031] In the SpringMVC framework, the Controller is used to receive requests sent from the browser or other client to the server, perform simple operations such as parameter conversion, return a response to the client, and finally implement specific business logic by calling the Service. The main functions of the Controller are: (1) Routing configuration: define the mapping relationship between the Controller class and method and the URL, and route the user request to the corresponding handler or method. (2) Processing requests: receive user requests and perform corresponding operations based on the type and parameters of the request, such as querying the database, calling other services, or generating a response. (3) Parameter binding: bind the parameters in the user request to the method parameters or objects for further processing. (4) Business logic: contains some business logic for processing user requests and generating responses. These logics may include validating user input, calling other services or modules, handling exceptions, etc. (5) View rendering: select a view to render (such as an HTML page, JSON data, etc.) and return it to the user to display the processing results.
[0032] S2. Encapsulate Service: Encapsulate a general Service that includes a general data processing flow for adding, deleting, modifying and checking data.
[0033] In the SpringMVC framework, Service is used to implement specific business logic. Its main responsibilities include processing business rules, data encapsulation, centralizing business logic, and improving testability. Definition and responsibilities of the Service layer: The Service layer is a business logic layer that is mainly responsible for processing the business logic in the application. Its main responsibilities include: (1) Processing business rules: validating data, performing calculations, and applying business logic. (2) Data encapsulation: hiding the underlying mechanism of the application and providing an abstract interface for other layers. (3) Centralizing business logic: centralizing all business logic in one location for easy maintenance and updating. (4) Improving testability: By separating business logic from other layers, business logic can be easily unit tested.
[0034] Implementation of the Service layer: To implement the Service layer in Java, you usually follow these steps:
[0035] (1) Create an interface: define the Service interface and declare the public methods to be provided.
[0036] (2) Create an implementation class: implement the Service interface and provide specific business logic implementation.
[0037] (3) Inject dependencies: Inject necessary dependencies (such as Repository) into the Service class through the dependency injection framework.
[0038] (4) Calling Service methods: Calling Service methods from the Controller layer or other layers to execute the required business logic.
[0039] S3. Data validation logic identification: define the annotation @Validator(entity, opt) to identify the data validation logic, entity is the entity name; opt is the operation to be performed on the entity; the annotation in this utility model refers to Java annotation, which is used to additionally mark the classes, methods, variables, parameters, etc. in the Java code.
[0040] S4. Define events to support business logic: By defining six types of events, namely, pre-addition events, post-addition events, pre-deletion events, post-deletion events, pre-modification events, and post-modification events, various business logics before and after data persistence are supported.
[0041] S5. Encapsulate the persistence operation of the Repository parent interface: Encapsulate a general Repository parent interface to perform data addition, deletion, modification and query persistence operations, and complete the encapsulation of the framework for quickly building addition, deletion, modification and query applications. The encapsulated Repository parent interface contains the general addition, deletion, modification and query data processing flow in step S2. Repository is specifically used to interact with the database to perform data addition, deletion, modification and query operations.
[0042] Example 2
[0043] Based on Example 1, this example sets the add, delete, modify and query request in step S1 to @RequestMapping(" / {entity} / {opt} / {id}"); the entity parameter is the entity name to be operated, which corresponds to the lowercase name of the entity class; the opt parameter is the operation to be performed on the entity, and its value range is: create, delete, update, query list, and query single data detail.
[0044] In this embodiment, the id parameter in the add, delete, modify and query request is only used when deleting, modifying or querying a single piece of data.
[0045] Example 3
[0046] In this embodiment, based on the embodiment 2, the general data processing flow of adding, deleting, modifying and checking in step S2 is specifically as follows:
[0047] (1) The data processing flow of the added data is as follows: front-end data submission, back-end data verification, pre-added logic, added data, and post-added logic;
[0048] (2) The data processing flow for deletion is as follows: front-end data submission, back-end data verification, pre-deletion logic, data deletion, and post-deletion logic;
[0049] (3) The modified data processing flow is as follows: front-end data submission, back-end data verification, pre-modification logic, data modification, and post-modification logic;
[0050] (4) The data processing flow of the query is as follows: the front end submits the request, the back end verifies the parameters, and then queries the data.
[0051] Example 4
[0052] This embodiment is based on the embodiment 3. In step S3, during the data verification process, when a certain data verification fails, a ValidateException is thrown to terminate the data processing flow; the corresponding data verification logic is searched and called through the @Validator annotation in the Service to implement the data verification process.
[0053] Example 5
[0054] In this embodiment, based on Embodiment 4, the annotations corresponding to the six types of events in step S4 are: @BeforeCreateEvent(entity), @AfterCreateEvent(entity), @BeforeDeleteEvent(entity), @AfterDeleteEvent(entity), @BeforeUpdateEvent(entity), @AfterUpdateEvent(entity); the corresponding data processing logic is searched and called in the Service through the above annotations.
[0055] In this embodiment, "calling corresponding data processing logic" or "calling corresponding data verification logic" refers to different entities, and their logic may be different. For example: User Entity, Enterprise Entity, when adding a new user, you need to fill in the name, mobile phone number, email address, etc., when adding a new enterprise, you need to fill in the enterprise name, social credit code, etc. The information filled in is different, so the verification logic or data processing logic is also different. Correspondingly, it is the verification logic or data processing logic corresponding to each entity.
[0056] In this embodiment, six types of events are used to support various business logics before and after data persistence, for example:
[0057] (1) Taking user registration as an example, the corresponding request is / user / create, the entity is user, and the operation is add, which means inserting a new record into the user table in the database. In business, other actions are often implied, such as setting a default role for the newly added user, adding default permissions, etc. In this case, the "post-add event" can be used to implement the function of adding default roles and default permissions.
[0058] (2) Take deleting a role as an example. The corresponding request is / role / delete / n. The entity is the role, the operation is delete, and the id is n. In the system, the data with id=n is deleted from the role table in the database. However, in business, it is often required that when deleting a role, if a user still has this role, the role must be cancelled for the user before it can be deleted. In this case, the "pre-deletion event" can be used to prevent the execution of the deletion action.
[0059] Example 6
[0060] In this embodiment, based on the embodiment 5, the Repository parent interface encapsulated in step S5 includes the new data, deleted data, modified data, and queried data in the general add, delete, modify, and query data processing flow in step S2.
[0061] Example 7
[0062] In this embodiment, based on the embodiment 6, the Repository parent interface encapsulated in step S5 dynamically generates a Reopsitory implementation class for each entity at runtime through ByteBuddy; the Service performs data addition, deletion, modification, query and persistence operations through the Repository parent interface. A Java class library can dynamically generate or modify Java classes at runtime.
[0063] Based on the above-mentioned embodiment 7, the following provides a framework encapsulation code for adding, deleting, modifying and checking data:
[0064] (1) Encapsulation data verification annotation:
[0065]
[0066] (2) Package added before event annotation:
[0067]
[0068] (3) Package added event annotation:
[0069]
[0070] (4) Events before encapsulation deletion:
[0071]
[0072] (5) Events after encapsulation deletion:
[0073]
[0074] (6) Events before encapsulation modification:
[0075]
[0076]
[0077] (7) Encapsulate the modified event:
[0078]
[0079] (8) Encapsulate Controller:
[0080]
[0081]
[0082]
[0083] (9) Encapsulation Service:
[0084]
[0085]
[0086]
[0087]
[0088]
[0089] (10) Encapsulate Repository:
[0090]
[0091] The above package is published separately as Spring Boot Starter. When developing a data addition, deletion, modification and query application, you only need to introduce the Starter and write the Entity code, data verification code, and logic code before and after data persistence to complete the construction.
[0092] In this embodiment, the framework obtained by the encapsulation method of the framework for quickly building a CRUD application based on the present invention can enable developers to avoid writing a large amount of templated repetitive code when building CRUD applications. Developers only need to focus on key points such as Entity, data verification logic, and logic before and after data persistence. The framework encapsulated by the method of the present invention can quickly build CRUD applications, thereby improving construction efficiency and avoiding complex and tedious construction processes.
[0093] The embodiments described above are merely descriptions of preferred implementation modes of the present invention, and are not intended to limit the concept and scope of the present invention. Without departing from the design concept of the present invention, various modifications and improvements made to the technical solutions of the present invention by ordinary engineering technicians in the field should fall within the protection scope of the present invention. The technical contents for which protection is sought in the present invention have been fully recorded in the technical requirements.
[0094] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0095] Obviously, those skilled in the art can make various changes and modifications to the embodiments of the present invention without departing from the spirit and scope of the embodiments of the present invention. Thus, if these modifications and variations of the embodiments of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A packaging method for quickly building a framework for adding, deleting, modifying and checking applications, characterized in that: The specific steps include: S1. Encapsulate Controller: Encapsulate a general Controller to intercept all entity addition, deletion, modification and query requests; S2. Encapsulate Service: Encapsulate a general Service that includes a general data processing flow for adding, deleting, modifying, and checking data; S3. Data validation logic identification: define the annotation @Validator(entity,opt) to identify the data validation logic, entity is the entity name; opt is the operation to be performed on the entity; S4. Define events to support business logic: By defining six types of events, namely, pre-addition event, post-addition event, pre-deletion event, post-deletion event, pre-modification event, and post-modification event, various business logics before and after data persistence are supported; S5. Encapsulate the persistence operation of the Repository parent interface: Encapsulate a general Repository parent interface to perform data addition, deletion, modification and query persistence operations, and complete the encapsulation of the framework for quickly building addition, deletion, modification and query applications. The encapsulated Repository parent interface contains the general addition, deletion, modification and query data processing flow in step S2.
2. According to claim 1, a packaging method for quickly building a framework for adding, deleting, modifying and checking applications is characterized by: In step S1, the add, delete, modify and query request is set to @RequestMapping(" / {entity} / {opt} / {id}"); the entity parameter is the entity name to be operated, which corresponds to the lowercase name of the entity class; the opt parameter is the operation to be performed on the entity, and the value range is: add create, delete delete, modify update, query list list, and query single data detail.
3. According to claim 2, a packaging method for quickly building a framework for adding, deleting, modifying and checking applications is characterized in that: The id parameter is only used when deleting, modifying, or querying a single piece of data.
4. According to claim 1, a packaging method for quickly building a framework for adding, deleting, modifying and checking applications is characterized by: The general data processing flow of adding, deleting, modifying and checking in step S2 is specifically as follows: (1) The data processing flow of the added data is as follows: front-end data submission, back-end data verification, pre-added logic, added data, and post-added logic; (2) The data processing flow for deletion is as follows: front-end data submission, back-end data verification, pre-deletion logic, data deletion, and post-deletion logic; (3) The modified data processing flow is as follows: front-end data submission, back-end data verification, pre-modification logic, data modification, and post-modification logic; (4) The data processing flow of the query is as follows: the front end submits the request, the back end verifies the parameters, and then queries the data.
5. The encapsulation method for quickly building a framework for adding, deleting, modifying and checking applications according to claim 1 is characterized in that: In the step S3, when a certain data verification fails, a ValidateException is thrown to terminate the data processing flow; in the Service, the corresponding data verification logic is searched and called through the @Validator annotation to implement the data verification process.
6. The encapsulation method for quickly building a framework for adding, deleting, modifying and checking applications according to claim 1, characterized in that: The annotations corresponding to the six types of events in step S4 are: @BeforeCreateEvent(entity), @AfterCreateEvent(entity), @BeforeDeleteEvent(entity), @AfterDeleteEvent(entity), @BeforeUpdateEvent(entity), @AfterUpdateEvent(entity); the corresponding data processing logic is searched and called in the Service through the above annotations.
7. The encapsulation method for quickly building a framework for adding, deleting, modifying and checking applications according to claim 1 is characterized in that: The Repository parent interface encapsulated in step S5 includes the new data, deleted data, modified data, and queried data in the general add, delete, modify, and query data processing flow in step S2.
8. The encapsulation method for quickly building a framework for adding, deleting, modifying and checking applications according to claim 1, characterized in that: The Repository parent interface encapsulated in step S5 dynamically generates a Reopsitory implementation class for each entity at runtime through ByteBuddy; the Service performs data addition, deletion, modification, query and persistence operations through the Repository parent interface.
Citation Information
Cited By
Method for constructing addition, deletion, modification and check interface for declarative metadata analysis
CN120315711A