JAVA lazy development: mybatis generator installation and use (spring tool suite)

Posted by benyamin on Mon, 04 May 2020 05:54:22 +0200

java lazy development: mybatis generator generates the corresponding entity class, xml Mapper file, interface and help class according to the table design in the database.

Take spring-tool-suite-3.9.2.RELEASE as an example:


Introduction package


Create mybatis generator configuration file

Modify mybatis generator configuration file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-// MyBatis Generator Configuration 1.0//EN" "">
  <context id="prod">
        <!-- RowBounds pagination -->
        <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" />
        <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
            <property name="suppressDate" value="true" />
            <property name="suppressAllComments" value="true" />

        <!-- jdbc Connect -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://" userId="root"
            password="1234" />
			<property name="forceBigDecimals" value="false" />
		<!-- targetProject:generate PO Location of class -->
        <javaModelGenerator targetPackage="com.lazy.develop.generator.entity" targetProject="lazyDevelop">
            <!-- enableSubPackages:Whether to let schema As suffix of package -->
			<property name="enableSubPackages" value="false" />
			<!-- Spaces before and after values returned from the database are cleaned up -->
			<property name="trimStrings" value="true" />
			<property name="comments" value="true"/>

        <!-- targetProject:mapper Location of map file generation -->
		<sqlMapGenerator targetPackage="com.lazy.develop.generator.mapper"  targetProject="lazyDevelop">
			<property name="enableSubPackages" value="false" />
		<!-- targetPackage: mapper Location of interface generation -->
		<javaClientGenerator type="XMLMAPPER" targetPackage="com.lazy.develop.generator.dao"  targetProject="lazyDevelop">
			<property name="enableSubPackages" value="false" />
		<!-- Specify database tables -->
		<table schema="" tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" 
		  enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
			<generatedKey column="id" sqlStatement="MySql" identity="true"/>

The construction of the project will not be written. It will be Ok if it is integrated into its own framework


If you have plug-ins in your editor, just right-click the mybatis generator configuration file to run it. If you do, run the following main method:

package com.mybatis.test;

import org.mybatis.generator.api.ShellRunner;

public class App {

    public static void main(String[] args) {
        args = new String[] { "-configfile", "src\\main\\resources\\generatorConfig.xml.xml", "-overwrite" };


Topics: Mybatis xml Database JDBC