SSM framework automatically generates code through mybatis generator (recommended)

1、 First, eclipse configures the Maven environment and creates an SSM framework project

2、 In POM Add plugin to XML

be careful:

1. Add a plug-in to POM in the < build > < / build > tab and specify the database driver here. Then configure generatorconfig. In the next step XML does not need to specify the local path of the database driver;

2、src/main/resources/mybatis-generator/generatorConfig. XML specifies generatorconfig. XML The path of XML configuration file can be adjusted according to your actual situation;

3、 Generatorconfig XML configuration file

Configuration explanation:

1. Classpathentry location does not need to be configured here, because the database driver has been configured in POM before;

2. JDBC connection configures the corresponding driver class, URL, user name and password according to its own database;

3. Javamodelgenerator, sqlmapgenerator and javaclientgenerator configure the corresponding POJO class to be generated, the XML file corresponding to Dao class and mapper, the targetpackage attribute specifies the package name, and targetproject specifies the path of its own project,

4. The table tag configures the mapping between database tables and entity classes. The tablename attribute specifies the table name, and the domainobjectname specifies the generated POJO class name< Property name = "useactualcolumnnames" value = "true" / > If configured, the property name of the generated entity class is the same as that of the database

The name of each field in the table is the same. If it is not configured, the field name in the data table will be passed_ The connected fields automatically generate the classic hump representation. For example, I have a field named type_ ID, the generated attribute name is typeID;

It is recommended that you use it when creating tables in the database_ Separate words;

4、 After creating, click Maven build

eject

Fill in mybatis generator: generate in goals, and then click Run

You can also enter MVN mybatis generator: generate from the Maven command line

5、 The results are as follows:

summary

The above is the SSM framework introduced to you by Xiaobian, which automatically generates code through mybatis generator. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>