This is the 14th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

preface

This section describes RuoYi – Vue code generation module is how to configure the generated code, its visual code editing mode for developers can well solve the problem of repeat code, just a key can be most duplicate code are generated, developers will be able to give their attention entirely on the writing of the business logic, Get rid of boring add, delete, change and check.

ruoyi-generator

In Ruoyi’s code, there’s a lot of module code that generates code,

With configuration, Controller, entity classes,mapper, Service,util and the corresponding template (Controller.java.vm), it’s actually a small project

GenConfigclass

This class uses @ConfigurationProperties directly to help populate the class with the corresponding configured YML properties.

@ConfigurationProperties(prefix = "gen")
@PropertySource(value = { "classpath:generator.yml" })
Copy the code

One to one correspondence

Code generation list interface

This interface is used to display data in the GEN_table table

The corresponding SQL is as follows

<where>
   <if test="tableName ! = null and tableName ! = "">
      AND lower(table_name) like lower(concat(The '%', #{tableName}, The '%')) < /if>
   <if test="tableComment ! = null and tableComment ! = "">
      AND lower(table_comment) like lower(concat(The '%', #{tableComment}, The '%')) < /if>
   <if test="params.beginTime ! = null and params.beginTime ! = ""> <! -- Start time retrieval -->AND date_format(create_time,'%y%m%d') &gt; = date_format(#{params.beginTime},'%y%m%d') < /if>
   <if test="params.endTime ! = null and params.endTime ! = ""> <! -- End time search -->AND date_format(create_time,'%y%m%d') &lt; = date_format(#{params.endTime},'%y%m%d') < /if>
</where>
Copy the code

Use the lower function to lower the input and table names to lowercase. We rarely write this because we usually search for Chinese, so we don’t need to lowercase, but here we do fuzzy search for table names. Table names are basically English, so we need to lower the input and table names to do fuzzy search.

Where params.beginTime is in BaseEntity

/** Request parameters */
private Map<String, Object> params;
Copy the code

To direct access to the front desk every time add date range is added directly to the Param parameter, each entity class so we don’t have to add the search parameters, actually brings some hidden trouble, because there is no way to verify they are correct or not, there is no way to detect the error parameters from the start, but are part of the development of energy saved.