Mybatis-plus reverse engineering to generate code-no error is reported, only the directory is generated without files

Background : mybatis-plus has the function of reverse engineering to generate mybatis mapper, dao, service, controller code according to the template.

Recurrence : The basic configuration of code generation is done, run, and there is nothing but the configured package directory is generated, but there is no actual code file below, and no error is reported in the console. Note that mybatis-puls logs are all in debug format, so nothing is printed, and there is no normal printing, but there is no error prompting the generated directory, which proves that half of the code is correct, so you have to debug the cause of the error.

Break point debug : finally trace to the getObjectMap method of AbstractTemplateEngine, line 195

return config.getInjectionConfig().prepareObjectMap(objectMap);

It is found that after the objectMap parameter is parsed, it is found that the injectionConfig parameter is a null pointer

Then the resulting null pointer exception

Therefore, an exception is caught and an error is thrown, causing the generation of the parse file to fail .

    } catch (Exception var11) {
            logger.error("无法创建文件,请检查配置信息!", var11);
        }

Check the official document: https://mp.baomidou.com/guide/generator.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BB%A3%E7%A0%81 %E6%A8%A1%E6%9D%BF

This is for custom attributes. You can set the parameter parsing file and replace it when generating the code. This is normal usage.

But I currently don't have any external custom attributes to use, so I didn't define this external parameter, which caused the InjectionConfig object to be null, and the resulting null pointer exception caused the program to be interrupted and file generation failed.

So whether it is used or not, just add this parameter according to the official document.

Summary : 1. Because the default log printing of mybatis-plus is not perfect, it is difficult to find errors, only debug. 2. The custom external parameter should be null if it is not used, but the requirement here must be null and there is no prompt, so it is an unreasonable error. 3. The solution is to add the custom attribute code on the official document.

Add the log configuration of mybatis-plus , plus this log generation prompt and it will be printed completely:

log4j.properties file, put it under src/main/resources

content:

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# MyBatis logging configuration...
log4j.logger.org.mybatis=TRACE
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p %d %C: - %m%n

 

Guess you like

Origin blog.csdn.net/Mint6/article/details/98476339