Automatic code generation of mybatis reverse engineering in mybatis framework

Mybatis is a semi-automatic orm. In using this framework, the biggest workload is to write the mapping file. Because manual writing is easy to make mistakes, we can use mybatis generator to help us automatically generate the file.

reverse engineering

1. What is reverse engineering

MySQL requires programmers to write their own SQL statements. Reverse engineering is officially provided by mybatis, which can automatically generate the code required by mybatis execution for a single table (mapper.java, mapper.xml, Po..)

In the actual development of enterprises, the commonly used reverse engineering method is to generate java code due to the table of the database.

2. Download reverse engineering

mybatis-generator-core-1.3. 2-bundle. zip

3. Method of use (able to use)

3.1 operation reverse engineering

Several methods of running reverse engineering provided in official documents

Running MyBatis Generator

MyBatis Generator (MBG) can be run in the following ways:

(1)From the command prompt with an XML configuration

(2)As an Ant task with an XML configuration

(3)As a Maven Plugin

(4)From another Java program with an XML configuration

(5)From another Java program with a Java based configuration

(6) You can also generate code through eclipse's plug-ins

It is recommended to use the from another Java program with an XML configuration without relying on development tools.

Next, create a project to generate reverse files, and then copy the automatically generated files to the original project (this is to prevent direct generation in the source file, which will overwrite the files with the same name). The screenshot of the imported jar package and project structure is as follows:

As shown in the figure

3.2 generate code configuration file

generatorConfig. xml:

3.3 execution generator

Generatorsqlmap. java:

Generated code:

3.4 using generated code

You need to copy the generated code in the generated project to your own project. Let's go here. Itemsmapper Java and itemsmapper The XML, items and itemsexample classes are copied into our original project.

Testing methods in itemsmapper

The above is the automatic code generation of mybatis reverse engineering of mybatis framework introduced by Xiaobian. I hope it will be helpful to you!

Recommended reading for programming tips:

Mybatis introductory learning tutorial (I) - mybatis quick start

In depth analysis on saving and reading of mybatis Oracle blob type fields

Dao and mapper of mybatis practice

Dynamic SQL and relational query in mybatis practice

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>