Remember my previous code generation tool, this time I upgraded it again

Upgrade again

Before I wrote a code generation tool myself, in order to save unnecessary work when creating entities. At that time, I upgraded this tool once. Interested students can read this article I wrote:

Remember my previous code generation tool, this time I upgraded it

The upgraded functions at that time can automatically generate Service, ServiceImpl, Controller and other classes, and customized development according to the actual situation. Such as the realization of the company framework interface, the company framework class.

This time I mainly upgraded:

Adding, deleting, modifying and checking code in the Service layer

Source description

Let's take a look at the code:

First, I added the following code to serviceImpl:

image

Here we look at a methodForServiceImplCreate(clazz, remarks)method:

image

First, we import the necessary annotation classes:

clazz.addImportedType(new FullyQualifiedJavaType("org.springframework.transaction.annotation.Transactional"));
        clazz.addImportedType(new FullyQualifiedJavaType("com.xxx.basic.framework.BusinessExceptionAssert"));

Then build the method createXXX():

Method createMethod = new Method("create" + modelName);

In the middle is the comment coding link.

Then we need to write service and controller methods.

effect

Let's take a look at the resulting effect.

xxxServiceImpl.java

Automatically generated creation method:

image

As shown in the figure above, comments, annotations, and methods are all automatically generated by the program.

In the same way, let's take a look at the query method.

image

Here I only wrote the list method and the page paging method.

Let's take a look at the service method:

image

Finally, the controller method:

image

Here I only wrote the create method, other methods can add functions to the generated code.

Of course, the above code is just a template, and the template is just for reference. In fact, the code may be changed according to requirements.

Okay, that's it for the upgrade introduction of the code generation tool.

Guess you like

Origin blog.csdn.net/wujialv/article/details/113251715