CN116303759A - A method, device, and storage medium for synchronizing entity object information - Google Patents
A method, device, and storage medium for synchronizing entity object information Download PDFInfo
- Publication number
- CN116303759A CN116303759A CN202211621297.4A CN202211621297A CN116303759A CN 116303759 A CN116303759 A CN 116303759A CN 202211621297 A CN202211621297 A CN 202211621297A CN 116303759 A CN116303759 A CN 116303759A
- Authority
- CN
- China
- Prior art keywords
- field
- model
- enhanced
- original model
- original
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/443—Optimisation
- G06F8/4434—Reducing the memory space required by the program code
- G06F8/4435—Detection or removal of dead or redundant code
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Software Systems (AREA)
- Computing Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Description
技术领域technical field
本发明属于计算机开发技术领域,尤其涉及一种实体对象信息同步方法、设备及存储介质。The invention belongs to the technical field of computer development, and in particular relates to an entity object information synchronization method, device and storage medium.
背景技术Background technique
随着编程工业化水平的不断加深,各种编程架构层出不穷(比如MVC、MVP、DDD等等),伴随着这些编程架构,在开发Java项目时,当代码分层处理后,POJO就会存在如VO、BO、PO、DO、DTO、DP等实体对象。传统的开发过程大致有两种:先定义表对应实体对象PO下的字段,然后拷贝这些字段代码到VO、BO、DTO等实体对象中。通过定义基础实体对象,其他实体对象继承该基础实体对象,但因为Java单继承的限制,仍然会存在重复的字段定义。With the continuous deepening of programming industrialization, various programming architectures emerge in an endless stream (such as MVC, MVP, DDD, etc.), along with these programming architectures, when developing Java projects, when the code is layered, POJO will exist like VO , BO, PO, DO, DTO, DP and other entity objects. There are roughly two traditional development processes: first define the fields under the table corresponding to the entity object PO, and then copy these field codes to entity objects such as VO, BO, and DTO. By defining the base entity object, other entity objects inherit the base entity object, but due to the limitation of Java single inheritance, there will still be repeated field definitions.
这些实体对象在某些程度存在大量的重复字段,当业务发生变更导致字段发生新增、修改、删除时,需要同步修改多个实体对象。否则会导致字段类型不一致或字段名不一致等问题,这种问题在不断的需求变更中尤为突出。如果没有能维护模型数据的一致性,导致使用时脏数据出现Bug,这一类的Bug通常较为隐蔽,且排查困难。These entity objects have a large number of repeated fields to some extent. When business changes cause fields to be added, modified, or deleted, multiple entity objects need to be modified synchronously. Otherwise, it will lead to problems such as inconsistent field types or inconsistent field names, which are especially prominent in the continuous change of requirements. If the consistency of the model data is not maintained, bugs will appear in the dirty data during use. This type of bug is usually hidden and difficult to troubleshoot.
目前,并没有一个完善的技术方案解决上述问题。例如MapStruct从数据出发,能够解决当两个对象存在字段不一致时,通过指定源模型字段和目标模型字段转换数据。但是仍然不能解决实体模型自身字段重复和字段可能存在不一致等问题。At present, there is no perfect technical solution to solve the above problems. For example, starting from the data, MapStruct can solve the problem of data conversion by specifying the source model field and the target model field when the fields of two objects are inconsistent. However, it still cannot solve the problems of duplication of fields in the entity model itself and possible inconsistencies in the fields.
发明内容Contents of the invention
本发明的技术目的是提供一种实体对象信息同步方法、设备及存储介质,以解决实体对象存在大量的重复定义字段技术问题。The technical purpose of the present invention is to provide a method, device and storage medium for synchronizing entity object information, so as to solve the technical problem of a large number of repeatedly defined fields in entity objects.
为解决上述问题,本发明的技术方案为:In order to solve the above problems, the technical solution of the present invention is:
一种实体对象信息同步方法,包括如下步骤:A method for synchronizing entity object information, comprising the steps of:
定义原始模型,原始模型为包括基础表、分页查询、带有业务含义的字段/变量类型;Define the original model, which includes basic tables, paging queries, and field/variable types with business meanings;
定义增强模型,增强模型为需要增加的字段/变量;Define the enhanced model, which is the field/variable that needs to be added;
获取原始模型的字段/变量定义语法树节点,通过注解处理器扫描增强模型的注解,根据增强模型注解里的属性,修改原始模型的字段/变量定义语法树节点,将修改后的字段/变量定义语法树节点添加到增强模型的类定义语法树节点中。Obtain the field/variable definition syntax tree node of the original model, scan the annotation of the enhanced model through the annotation processor, modify the field/variable definition syntax tree node of the original model according to the attributes in the enhanced model annotation, and define the modified field/variable A syntax tree node is added to the class definition syntax tree node of the augmented model.
具体地,基础表字段/变量类型包括创建用户、更新用户、创建时间和更新时间;分页查询字段/变量类型包括页号、页大小和模糊搜索关键字;带有业务含义的字段/变量类型包括名称、唯一key、编码和逻辑删除标志。Specifically, basic table field/variable types include creating user, updating user, creation time, and update time; paging query field/variable types include page number, page size, and fuzzy search keywords; field/variable types with business meaning include Name, unique key, encoding, and tombstone flag.
较优地,在使用注解处理器前,预先定义有三个注解,分别为@Mode l、@Mode l Fi e l d和@EnhanceMode l;Preferably, before using the annotation processor, three annotations are predefined, namely @Mode l, @Mode l Fi e l d and @EnhanceMode l;
在定义原始模型时,利用@Mode l在原始模型的类上进行注解,并利用@Mode l Fi e l d在原始模型的字段进行标注;When defining the original model, use @Model l to annotate the class of the original model, and use @Mode l Field to annotate the field of the original model;
在定义增强模型时,利用@EnhanceMode l在增强模型的类上进行注解;若增强模型的自身字段需要字段名称或者表字段名,则利用@Mode l F i e l d在增强模型的自身字段上进行注解。When defining an enhanced model, use @EnhanceMode l to annotate the class of the enhanced model; if the enhanced model's own field needs a field name or table field name, use @Mode l Field to annotate the enhanced model's own field.
其中,定义增强模型具体包括如下步骤:定义复制部分原始模型的字段/变量类型;定义忽略部分原始模型的字段;定义是否复制原始模型的字段的swagger注解;定义是否复制原始模型的字段的JSR303注解;定义复制部分原始模型的字段注解不复制。Among them, defining the enhanced model specifically includes the following steps: defining the field/variable type of copying part of the original model; defining the field of ignoring part of the original model; defining whether to copy the swagger annotation of the field of the original model; defining whether to copy the JSR303 annotation of the field of the original model ; Field annotations defining the copied part of the original model are not copied.
具体地,注解器处理器执行时包括如下步骤Specifically, the execution of the annotation processor includes the following steps
扫描存在@EnhanceMode注解的TypeE l ement列表,遍历TypeE l ement列表,依次处理存在@EnhanceMode l注解类;Scan the list of TypeE l element with @EnhanceMode annotation, traverse the list of TypeE l element, and process the classes with @EnhanceMode l annotation in turn;
基于@Enhance Mode l下的from属性,获取原始模型的TypeE l ement,从TypeE lement中获取原始模型字段的Var i ab l eE l ement列表;根据@Enhance Mode l下的ignoreF i e l ds属性,过滤忽略的字段;根据@EnhanceMode l下的enab l eSwagger属性,判断是否忽略swagger相关注解;根据@EnhanceMode l下的enab l eJSR属性,判断是否忽略JSR303注解;根据@EnhanceMode l下的d i sab l eAnnotat i on属性,忽略部分指定注解;根据字段上定义@Mode l F i e l d注解,生成字段名称静态变量和表字段名静态变量。Obtain the TypeE l element of the original model based on the from attribute under @Enhance Model l, and obtain the Var i ab l eE l element list of the original model field from the TypeE element; filter and ignore according to the ignoreFi e l ds attribute under @Enhance Model l field; according to the enab l eSwagger attribute under @EnhanceMode l, judge whether to ignore swagger related annotations; according to the enab l eJSR attribute under @EnhanceMode l, judge whether to ignore JSR303 annotations; according to d i sab l eAnnotat i on under @EnhanceMode l Attribute, ignoring some specified annotations; according to the @Mode lField annotation defined on the field, a field name static variable and a table field name static variable are generated.
其中,若将修改后的字段/变量定义语法树节点添加到增强模型的类定义语法树节点中过程中,存在原始模型与增强模型之间存在同名字段,判断若增强模型存在相同字段名,则直接使用增强模型的字段;若增强模型不存在相同的字段名,则编译错误,对增强模型冗余该字段的定义。Among them, if there is a field with the same name between the original model and the enhanced model during the process of adding the modified field/variable definition syntax tree node to the class definition syntax tree node of the enhanced model, it is judged that if the enhanced model has the same field name, then Use the field of the enhanced model directly; if the enhanced model does not have the same field name, it will cause a compilation error, and the definition of the field is redundant for the enhanced model.
进一步优选地,支持采用I nte l l i J I DEA外部插件实现实体对象信息同步方法,步骤如下:通过from属性获取原始模型;获取原始模型中带有@Mode l F i e l d的字段;添加带有@Mode l F i e l d的原始模型字段到增强模型;添加字段名称静态变量以及表字段名静态变量。Further preferably, the method of synchronizing entity object information by using an external plug-in of I nte l l i J IDEA is supported, and the steps are as follows: obtain the original model through the from attribute; obtain the field with @Mode l F i e l d in the original model; add the field with @Mode l The original model field of F i e l d is added to the enhanced model; add the field name static variable and the table field name static variable.
一种电子设备,电子设备包括处理器和存储器,存储器上存储有可在处理器上运行的计算机指令,处理器用于调用存储器中的计算机指令执行如上述的实体对象信息同步方法。An electronic device, the electronic device includes a processor and a memory, the memory stores computer instructions that can run on the processor, and the processor is used to call the computer instructions in the memory to execute the above entity object information synchronization method.
一种存储介质,存储介质用于存储计算机指令,其中,在计算机指令运行时控制存储介质所在设备执行如上述的实体对象信息同步方法。A storage medium is used to store computer instructions, wherein when the computer instructions are running, the device where the storage medium is located is controlled to execute the above entity object information synchronization method.
本发明由于采用以上技术方案,使其与现有技术相比具有以下的优点和积极效果:Compared with the prior art, the present invention has the following advantages and positive effects due to the adoption of the above technical scheme:
本发明能解决实体模型字段重复,以及当业务发生变化导致字段发生变化时,开发人员只需要专注原始模型,而无需关心其他实体对象,其他实体对象可以在编译时同步原始模型字段变化,实现将原始模型的字段快速复制到增强模型中。能够很大程度减少重复代码和出现字段不一致等情况,同时可提高代码的清晰度、提升项目的可维护性和可扩展性。此外,能适用于所有IntelliJ IDE开发的Java项目,使用简单,只需添加几个注解即可使用。The present invention can solve the duplication of fields in the entity model, and when the field changes due to business changes, the developer only needs to focus on the original model and does not need to care about other entity objects. Other entity objects can synchronize the field changes of the original model at compile time, realizing the Fields from the original model are quickly copied into the augmented model. It can greatly reduce repeated code and field inconsistency, and at the same time improve the clarity of the code, and improve the maintainability and scalability of the project. In addition, it can be applied to Java projects developed by all IntelliJ IDEs. It is easy to use and can be used by adding a few annotations.
附图说明Description of drawings
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiment. The drawings are only for the purpose of illustrating a preferred embodiment and are not to be considered as limiting the invention.
图1为本发明的一种实体对象信息同步方法的流程框架图;Fig. 1 is a flow frame diagram of a method for synchronizing entity object information of the present invention;
图2为本发明的定义模型的流程框架图;Fig. 2 is the flowchart of the definition model of the present invention;
图3为本发明的注解处理器实施的流程框架图;Fig. 3 is a flow frame diagram of the implementation of the annotation processor of the present invention;
图4为本发明的插件实施流程图;Fig. 4 is the plug-in implementation flowchart of the present invention;
图5为本发明的业务模型的示意图;Fig. 5 is a schematic diagram of the business model of the present invention;
图6为本发明的另一业务模型的示意图。Fig. 6 is a schematic diagram of another business model of the present invention.
具体实施方式Detailed ways
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对照附图说明本发明的具体实施方式。显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图,并获得其他的实施方式。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the specific implementation manners of the present invention will be described below with reference to the accompanying drawings. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention, and those skilled in the art can obtain other accompanying drawings based on these drawings and obtain other implementations.
为使图面简洁,各图中只示意性地表示出了与本发明相关的部分,它们并不代表其作为产品的实际结构。另外,以使图面简洁便于理解,在有些图中具有相同结构或功能的部件,仅示意性地绘示了其中的一个,或仅标出了其中的一个。在本文中,“一个”不仅表示“仅此一个”,也可以表示“多于一个”的情形。In order to make the drawing concise, each drawing only schematically shows the parts related to the present invention, and they do not represent the actual structure of the product. In addition, to make the drawings concise and easy to understand, in some drawings, only one of the components having the same structure or function is schematically shown, or only one of them is marked. Herein, "a" not only means "only one", but also means "more than one".
以下结合附图和具体实施例对本发明提出的一种实体对象信息同步方法、设备及存储介质作进一步详细说明。根据下面说明和权利要求书,本发明的优点和特征将更清楚。A method, device, and storage medium for synchronizing entity object information proposed by the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. Advantages and features of the present invention will be apparent from the following description and claims.
实施例Example
参看图1至图5,本实施例提供一种实体对象信息同步方法,使得增强模型能够对原始模型的字段自动进行复制。当原始模型字段发生变化时,无需修改增强模型也能同步变化。包括如下步骤:Referring to FIG. 1 to FIG. 5 , this embodiment provides a method for synchronizing entity object information, so that the enhanced model can automatically copy the fields of the original model. When the fields of the original model change, the changes can be synchronized without modifying the enhanced model. Including the following steps:
首先,参看图1和图2,需要定义原始模型,在定义原始模型时,利用@Mode l在原始模型的类上进行注解,并利用@Mode l F i e l d在原始模型的字段进行标注。在加上@Mode l F i e l d之后,当增强模型依赖原始模型时,除了会复制字段,同时,会生成该字段名称和表字段名静态变量。原始模型为定义的基础类,本身是一个POJO,其字段可以被增强模型复制。具体地,原始模型内的字段可以是一些基础的表字段类型,包括但不限于:id、createUser(创建用户)、updateUser(更新用户)、createDate(创建时间)、updateDate(更新时间)等。也可以包含在分页查询数据时的pageNo(页号)、pageS i ze(页大小)、searchKey(模糊搜索关键字)等。同时,也可以是一些带有业务含义的基础类型,包括但不限于:name(名称)、key(唯一key)、code(编码)、de l eteF l ag(逻辑删除标志)等。在本实施例中,原始模型可以是任何POJO类型,只要开发人员认为存在属性可以被其他POJO复用的情况,均可以定义为原始模型。First, referring to Figure 1 and Figure 2, the original model needs to be defined. When defining the original model, use @Model l to annotate the class of the original model, and use @Model F i e l d to mark the fields of the original model. After adding @Mode lField, when the enhanced model depends on the original model, in addition to copying the field, at the same time, the field name and table field name static variables will be generated. The original model is a defined base class, itself a POJO whose fields can be copied by the enhanced model. Specifically, the fields in the original model can be some basic table field types, including but not limited to: id, createUser (create user), updateUser (update user), createDate (creation time), updateDate (update time), etc. It can also include pageNo (page number), pageSize (page size), searchKey (fuzzy search keyword) and so on when querying data in pages. At the same time, it can also be some basic types with business meanings, including but not limited to: name (name), key (unique key), code (encoding), del eteF lag (logic deletion flag), etc. In this embodiment, the original model can be any POJO type, as long as the developer thinks there are situations where attributes can be reused by other POJOs, they can be defined as the original model.
接着,参看图1和图2,定义增强模型,增强模型为需要增加的字段/变量,本身也是一个POJO,但是可通过注解处理器(APT)工具,修改抽象语法树(AST),复制原始模型定义的字段到增强模型内,同时增强模型原有的字段不受编译的影响。在定义增强模型时,利用@EnhanceMode l在增强模型的类上进行注解;若增强模型的自身字段需要字段名称或者表字段名,则利用@Mode l F i e l d在增强模型的自身字段上进行注解。Next, refer to Figure 1 and Figure 2 to define the enhanced model. The enhanced model is the field/variable that needs to be added. It is also a POJO itself, but the abstract syntax tree (AST) can be modified through the annotation processor (APT) tool to copy the original model. The defined fields are added to the enhanced model, and the original fields of the enhanced model are not affected by compilation. When defining an enhanced model, use @EnhanceMode l to annotate the class of the enhanced model; if the enhanced model's own field needs a field name or table field name, use @Mode l Field to annotate the enhanced model's own field.
具体包括如下步骤:定义复制部分原始模型的字段/变量类型;定义忽略部分原始模型的字段;定义是否复制原始模型的字段的swagger注解;定义是否复制原始模型的字段的JSR303注解;定义复制部分原始模型的字段注解不复制。Specifically, it includes the following steps: define the field/variable type of copying part of the original model; define the field that ignores part of the original model; define whether to copy the swagger annotation of the field of the original model; define whether to copy the JSR303 annotation of the field of the original model; define the copy part of the original Model field annotations are not copied.
@EnhanceMode l属性解释如表1所示@EnhanceMode l attribute explanation is shown in Table 1
表1Table 1
参看图1和图3,在项目进行编译时,注解处理器APT通过扫描代码里的增强模型的注解,根据增强模型注解里的属性,首先获取原始模型的字段/变量定义语法树节点,然后按照注解属性的定义修改原始模型的字段/变量定义语法树节点,最后将修改后的语法树节点添加到增强模型的类定义语法树节点中。APT处理后新增的字段支持Lombok、MapStruct等注解,如增加Lombok的@Getter、@Setter注解后,新增的字段也会生成对应的getter()、setter()方法,MapStruct同理,增加@Mapper注解后,在对象数据转换时,也会生成新增的字段转换。Referring to Figure 1 and Figure 3, when the project is being compiled, the annotation processor APT scans the annotations of the enhanced model in the code, and according to the attributes in the annotations of the enhanced model, first obtains the field/variable definition syntax tree nodes of the original model, and then follows The definition of the annotation attribute modifies the field/variable definition syntax tree node of the original model, and finally adds the modified syntax tree node to the class definition syntax tree node of the enhanced model. The newly added fields after APT processing support annotations such as Lombok and MapStruct. For example, after adding @Getter and @Setter annotations of Lombok, the newly added fields will also generate corresponding getter() and setter() methods. MapStruct is the same, adding @ After Mapper annotations, new field conversions will also be generated during object data conversion.
原始模型和增强模型可以来自不同的模块,只要能通过maven依赖到即可,若将修改后的字段/变量定义语法树节点添加到增强模型的类定义语法树节点中过程中,存在原始模型与增强模型之间存在同名字段,则判断若增强模型存在相同字段名,则直接使用增强模型的字段,而不从原始模型复制字段。若增强模型不存在相同的字段名,而依赖的多个原始模型存在相同的字段名,则编译错误,用户可对增强模型冗余该字段的定义。The original model and the enhanced model can come from different modules, as long as they can be depended on by maven. If the modified field/variable definition syntax tree node is added to the class definition syntax tree node of the enhanced model, the original model and If there are fields with the same name between the enhanced models, it is judged that if the enhanced models have the same field name, the fields of the enhanced model will be used directly instead of copying the fields from the original model. If the enhanced model does not have the same field name, but the dependent original models have the same field name, a compilation error occurs, and the user can redundantly define the field for the enhanced model.
具体地,参看图3,APT可以用来在编译时扫描、编译和处理注解。详细步骤如下:扫描存在@EnhanceMode注解的TypeE l ement列表,遍历TypeE l ement列表,依次处理存在@EnhanceMode l注解类;基于@Enhance Mode l下的from属性,获取原始模型的TypeE lement,从TypeE l ement中获取原始模型字段的Var i ab l eE l ement列表;根据@Enhance Mode l下的i gnoreFi e l ds属性,过滤忽略的字段;根据@EnhanceMode l下的enab l eSwagger属性,判断是否忽略swagger相关注解;根据@EnhanceMode l下的enab leJSR属性,判断是否忽略JSR303注解;根据@EnhanceMode l下的d i sab l eAnnotat ion属性,忽略部分指定注解;根据字段上定义@Mode l Fie l d注解,生成字段名称静态变量和表字段名静态变量。Specifically, referring to Figure 3, APT can be used to scan, compile and process annotations at compile time. The detailed steps are as follows: Scan the list of TypeE l lems with @EnhanceMode annotations, traverse the list of TypeE l lems, and process the classes with @EnhanceMode l annotations sequentially; based on the from attribute under @EnhanceMode l, obtain the TypeE element of the original model, from TypeE l Obtain the Var i ab l eE l element list of the original model field in ment; filter the ignored fields according to the ignoreFi e l ds attribute under @EnhanceMode l; judge whether to ignore swagger related according to the enab l eSwagger attribute under @EnhanceMode l Annotation; judge whether to ignore the JSR303 annotation according to the enable JSR attribute under @EnhanceMode l; ignore some specified annotations according to the d i sab l eAnnotation attribute under @EnhanceMode l; generate the field name according to the @Mode l Field annotation defined on the field Static variables and table field names Static variables.
较优地,参看图4,由于APT在编译期实现扫描、编译和处理Java注解,当使用Intel l iJ IDEA编写代码时,无法识别和处理@Mode l、@Mode l F ie l d、@EnhanceModel等注解。为支持开发人员在I nte l l i J IDEA正常开发,本专利提供了插件并发布到了插件市场,开发人员只需下载安装该插件到自己的I nte l l i J I DEA上即可。当I nte ll i J IDEA安装插件后,插件的处理逻辑步骤如下:通过from属性获取原始模型;获取原始模型中带有@Mode l F ie l d的字段;添加带有@Mode l Fie l d的原始模型字段到增强模型;添加字段名称静态变量以及表字段名静态变量。同时,为了支持开发人员在I nte ll i J I DEA的structure Too l wi ndow看到对应POJO字段和变量,我们实现了I nte ll i JI DEA的StructureVi ewExtensi on接口,处理逻辑和上述插件处理逻辑一致。Preferably, referring to Figure 4, since APT scans, compiles, and processes Java annotations during compilation, when using Intel l iJ IDEA to write code, it cannot recognize and process @Mode l, @Mode lField, @EnhanceModel, etc. annotation. In order to support developers to develop normally in Intel l l i J IDEA, this patent provides a plug-in and publishes it to the plug-in market. Developers only need to download and install the plug-in on their own Intel l l i J IDEA. After installing the plug-in in I nte ll i J IDEA, the processing logic steps of the plug-in are as follows: get the original model through the from attribute; get the fields with @Mode l F ie l d in the original model; add the original with @Mode l Fie l d Model fields to augmented models; add field name static variables as well as table field name static variables. At the same time, in order to support developers to see the corresponding POJO fields and variables in the structure tool window of Inte ll i J IDEA, we have implemented the StructureViewExtension interface of Inte ll i JI DEA, and the processing logic is consistent with the above plug-in processing logic .
参看图5和图6,现对本是实施例的实际应用进行举例说明,例如在电商行业里,参数在使用过程中,需要发送商品、订单、实例等多个服务,因而存在大量重复参数,并且,因不同领域间需要进行实体对象转换,因而也存在大量的参数赋值的操作。如图5所示,将商品详细描述等大字段单独保存,提升查询性能,那么在这样的场景下,商品明细就要包含商品基础信息和商品扩展信息的字段。如图6所示,在查询数据时,除了字段来源于商品基础信息和商品扩展信息,可能还需要分页基础信息,因此,本实施例支持增强模型的字段可以来自多个原始模型。Referring to Figure 5 and Figure 6, an example is given to illustrate the actual application of this embodiment. For example, in the e-commerce industry, during the use of parameters, multiple services such as commodities, orders, and instances need to be sent, so there are a large number of repeated parameters. Moreover, due to the need for entity object conversion between different fields, there are also a large number of parameter assignment operations. As shown in Figure 5, large fields such as product detailed descriptions are stored separately to improve query performance. In such a scenario, the product details must include fields for basic product information and extended product information. As shown in FIG. 6 , when querying data, in addition to fields derived from commodity basic information and commodity extended information, pagination basic information may also be required. Therefore, the fields supporting the enhanced model in this embodiment can come from multiple original models.
首先原始模型定义,确定哪些商品字段可以作为原始模型字段信息:First, define the original model to determine which product fields can be used as original model field information:
1.商品基础信息:商品存在商品id(itemI d)、商品标题(t it l e),以及商品价格(pr ice)信息,这些基础信息可能存在商品表里面。1. Commodity basic information: Commodity has commodity id (itemI d), commodity title (t it l e), and commodity price (price) information, and these basic information may be stored in the commodity table.
2.商品扩展信息:为了提高查询性能,商品描述等一些大字段单独保存,这些信息可能保存在商品扩展表里面。2. Product extension information: In order to improve query performance, some large fields such as product description are stored separately, and these information may be stored in the product extension table.
因此,开发人员可以定义商品两个原始模型,分别为:商品基础原始模型ItemBasic和商品扩展原始模型ItemExtra。Therefore, developers can define two original models of items, namely: ItemBasic and ItemExtra.
此外,用户在查询时,需要分页信息,所以还需要定义分页原始模型BasePage。In addition, users need paging information when querying, so the original paging model BasePage needs to be defined.
接着对增强模型定义和处理,开发人员在开发商品业务时,需要使用对应的DTO实体对象,定义为ItemDTO。并且ItemDTO需要ItemBas i c和ItemExtra下的字段信息、不需要字段上对应的swagger对应注解信息、JSR303对应注解信息、以及@Length注解信息、同时也不需要ItemExtra下的extraF ie l d信息。用户在发起查询请求时,定义的ItemQuery查询实体除了需要ItemBas i c和ItemExtra下的字段信息,还需要对应的分页信息。在开发订单业务时,订单的DTO实体对象OrderDTO可能需要ItemBas i c下的字段信息,但是它自身也有一些字段信息,比如订单编号,订单名称等。Then define and process the enhanced model. Developers need to use the corresponding DTO entity object when developing commodity business, which is defined as ItemDTO. And ItemDTO needs the field information under ItemBasic and ItemExtra, does not need the corresponding swagger annotation information on the field, JSR303 corresponding annotation information, and @Length annotation information, and does not need the extraField information under ItemExtra. When the user initiates a query request, the defined ItemQuery query entity needs not only the field information under ItemBasic and ItemExtra, but also the corresponding paging information. When developing the order business, the DTO entity object OrderDTO of the order may need field information under ItemBasic, but it also has some field information, such as order number, order name, etc.
如上文示例,当字段需要发生变更,需要把t it l e改为name;或者需求发生变更,商品需要增加唯一编号itemNo,同时订单也需要同步记录商品编号。在本实施例中,仅需要修改原始模型ItemBas i c将t it l e修改为name,并新增一个itemNo字段,增强模型则会自动同步字段变化。As in the above example, when the field needs to be changed, you need to change t it l e to name; or if the demand changes, the product needs to add a unique number itemNo, and the order also needs to record the product number synchronously. In this embodiment, it is only necessary to modify the original model ItemBasic to change t it l e to name, and add an itemNo field, and the enhanced model will automatically synchronize field changes.
在本实施例中,增强模型生成的字段同时支持Lombok和MapStruct功能,所以开发人员在增强模型定义Lombok和MapStruct的注解时,也能适用。Lombok适用:在ItemDeta ilQuery增强模型上,加上@Data注解。MapStruct适用:增强模型生成的字段字段也能使用MapStruct进行属性的赋值,其次,如果出现字段名不一致时可以通过本实施例生成静态变量获取字段名称。In this embodiment, the fields generated by the enhanced model support Lombok and MapStruct functions at the same time, so developers can also apply when defining the annotations of Lombok and MapStruct in the enhanced model. Applicable to Lombok: Add the @Data annotation to the ItemDeta ilQuery enhanced model. MapStruct is applicable: the field fields generated by the enhanced model can also use MapStruct to assign attributes, and secondly, if there is an inconsistency in the field names, the static variables can be generated through this embodiment to obtain the field names.
倘若现在存在一个需求,用户在下订单的时候,因订单名称没有地方输入,所以想实现将商品名称赋值给订单名称。在MapStruct做数据转换的的时候,需要通过编写代码完成,编写代码时,可以通过ItemDTO.itemName_fie l d、OrderDTO.orderName_f ie l d获取字段名称。If there is a demand now, when the user places an order, because there is no place to enter the order name, he wants to assign the product name to the order name. When MapStruct performs data conversion, it needs to be completed by writing code. When writing code, you can obtain the field name through ItemDTO.itemName_field and OrderDTO.orderName_field.
更进一步的,本实施例还提供一种电子设备,电子设备包括处理器和存储器,存储器上存储有可在处理器上运行的计算机指令,处理器用于调用存储器中的计算机指令执行如上述的实体对象信息同步方法。Further, this embodiment also provides an electronic device, the electronic device includes a processor and a memory, the memory stores computer instructions that can be run on the processor, and the processor is used to invoke the computer instructions in the memory to execute the above entity Object information synchronization method.
此外,本实施例还提供一种存储介质,存储介质用于存储计算机指令,其中,在计算机指令运行时控制存储介质所在设备执行如上述的实体对象信息同步方法。In addition, this embodiment also provides a storage medium, which is used to store computer instructions, wherein when the computer instructions are running, the device where the storage medium is located is controlled to execute the above entity object information synchronization method.
上面结合附图对本发明的实施方式作了详细说明,但是本发明并不限于上述实施方式。即使对本发明作出各种变化,倘若这些变化属于本发明权利要求及其等同技术的范围之内,则仍落入在本发明的保护范围之中。The embodiments of the present invention have been described in detail above with reference to the accompanying drawings, but the present invention is not limited to the above embodiments. Even if various changes are made to the present invention, if these changes fall within the scope of the claims of the present invention and equivalent technologies, they still fall within the protection scope of the present invention.
Claims (9)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211621297.4A CN116303759A (en) | 2022-12-16 | 2022-12-16 | A method, device, and storage medium for synchronizing entity object information |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202211621297.4A CN116303759A (en) | 2022-12-16 | 2022-12-16 | A method, device, and storage medium for synchronizing entity object information |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN116303759A true CN116303759A (en) | 2023-06-23 |
Family
ID=86834770
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202211621297.4A Pending CN116303759A (en) | 2022-12-16 | 2022-12-16 | A method, device, and storage medium for synchronizing entity object information |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN116303759A (en) |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117234500A (en) * | 2023-10-20 | 2023-12-15 | 浙江常青树信息技术有限责任公司 | Model multi-inheritance method and device implemented by using java language and computer readable storage medium |
| CN117290445A (en) * | 2023-09-27 | 2023-12-26 | 中国建设银行股份有限公司 | Data processing methods, devices, equipment and media used in transaction data synchronization |
| CN119166117A (en) * | 2024-08-29 | 2024-12-20 | 广州赛意信息科技股份有限公司 | Metamodel processing method, device and medium in IDEA development environment |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20090064091A1 (en) * | 2005-06-27 | 2009-03-05 | Albert Donald Tonkin | Code transformation |
| US20130339930A1 (en) * | 2012-06-18 | 2013-12-19 | South Dakota Board Of Regents | Model-based test code generation for software testing |
| CN107741847A (en) * | 2017-10-11 | 2018-02-27 | 江苏千米网络科技股份有限公司 | Realize the method and device of domain-driven model |
-
2022
- 2022-12-16 CN CN202211621297.4A patent/CN116303759A/en active Pending
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20090064091A1 (en) * | 2005-06-27 | 2009-03-05 | Albert Donald Tonkin | Code transformation |
| US20130339930A1 (en) * | 2012-06-18 | 2013-12-19 | South Dakota Board Of Regents | Model-based test code generation for software testing |
| CN107741847A (en) * | 2017-10-11 | 2018-02-27 | 江苏千米网络科技股份有限公司 | Realize the method and device of domain-driven model |
Non-Patent Citations (3)
| Title |
|---|
| ALEXEY SVYATKOVSKIY, SARAH FAKHOURY, NEGAR GHORBANI, TODD MYTKOWICZ, ELIZABETH DINELLA, CHRISTIAN BIRD, JINU JANG, NEEL SUNDARESAN: "Program Merge Conflict Resolution via Neural Transformers", 《HTTPS://DOI.ORG/10.1145/3540250.3549163》, 29 November 2022 (2022-11-29) * |
| 佚名: "基于注解处理器开发自动生成getter和setter方法的插件", Retrieved from the Internet <URL:《https://developer.aliyun.com/article/867968》> * |
| 佚名: "注解的概念及自定义Java注解并实现注解给字段赋值", Retrieved from the Internet <URL:《https://blog.csdn.net/LwinnerG/article/details/108932681》> * |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117290445A (en) * | 2023-09-27 | 2023-12-26 | 中国建设银行股份有限公司 | Data processing methods, devices, equipment and media used in transaction data synchronization |
| CN117234500A (en) * | 2023-10-20 | 2023-12-15 | 浙江常青树信息技术有限责任公司 | Model multi-inheritance method and device implemented by using java language and computer readable storage medium |
| CN119166117A (en) * | 2024-08-29 | 2024-12-20 | 广州赛意信息科技股份有限公司 | Metamodel processing method, device and medium in IDEA development environment |
| CN119166117B (en) * | 2024-08-29 | 2025-06-24 | 广州赛意信息科技股份有限公司 | Meta model processing method, device and medium under IDEA development environment |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN109840429B (en) | Smart contract deployment, invocation methods and devices | |
| US10698682B1 (en) | Computerized software development environment with a software database containing atomic expressions | |
| CN116303759A (en) | A method, device, and storage medium for synchronizing entity object information | |
| CN107918666A (en) | Method of data synchronization and system on a kind of block chain | |
| WO2015078343A1 (en) | Development method for web development system, and web development system | |
| US20080250394A1 (en) | Synchronizing external documentation with code development | |
| WO2022166669A1 (en) | Hook method and apparatus at compile time, device, and storage medium | |
| CN106844643A (en) | A kind of Database Dynamic generation method based on template engine | |
| CN113360156B (en) | An IOS compilation method and related equipment | |
| CN103593197A (en) | Method and device for generating codes | |
| CN115756451B (en) | A method, device, equipment and storage medium for reusing multi-project code files | |
| JP2009507269A (en) | Code generation pattern | |
| CN103034486A (en) | Automatic optimization method based on full-system expansion call graph for mobile terminal operation system | |
| US20070079299A1 (en) | Method, apparatus and program storage device for representing eclipse modeling framework (EMF) ecore models in textual form | |
| US8935657B2 (en) | Model-to-model transformation by kind | |
| EP4336348A1 (en) | Iterative and interactive method for code conversion | |
| CN111984300B (en) | Code copying method and device, electronic equipment and computer readable storage medium | |
| CN110162299A (en) | Web program and its Quick Development Framework, development approach and relevant device | |
| CN105335161B (en) | It is a kind of from TASM time abstractions state machine to extension NTA automatic machines conversion method | |
| CN101055521B (en) | Mapping rule visualized generation method and system | |
| CN109558121A (en) | Development approach, device, equipment and the storage medium of interface drive program | |
| CN107408054A (en) | Flow control for language-embedded programming in general-purpose computing graphics processing units | |
| CN101770508B (en) | Data access method in mobile communication terminal and equipment thereof | |
| WO2025145849A1 (en) | Application program processing method and apparatus, computer device and storage medium | |
| CN114816475B (en) | Method, device, equipment and medium for updating embedded operating system |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |