MyBatis Plus 自动生成代码

pom jar包配置



	com.baomidou
	mybatis-plus-generator
	3.5.3.1




	com.baomidou
	mybatis-plus
	3.5.3.1




	mysql
	mysql-connector-java
	8.0.33




	org.freemarker
	freemarker
	2.3.32




	org.apache.velocity
	velocity
	1.7




	org.slf4j
	slf4j-api
	2.0.7

生成代码

package com.demo.mybatisplus.generator;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;

import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.Arrays;



public class Generator {

    public static void main(String[] args) {
        DataSourceConfig dsc = new DataSourceConfig.Builder("jdbc:mysql://localhost:3306/manage", "root", "1234567").build();
        AutoGenerator autoGenerator = new AutoGenerator(dsc);
        //1、全局配置
        String projectPath = System.getProperty("user.dir");
        String filePath = projectPath + "/src/main/java";
//        String filePathRe = projectPath + "/src/main/resources";

        GlobalConfig gc = new GlobalConfig.Builder()
                .author("baomidou")
                .outputDir(filePath)
                .dateType(DateType.ONLY_DATE)
                .build();

        autoGenerator.global(gc);

        PackageConfig pc = new PackageConfig.Builder()
                .controller("controller")
                .mapper("dao")
                .service("service")
                .serviceImpl("service.impl")
                .xml("dao.xml")
				//改成自己对应的包路径
                .parent("com.xxx.xxx")
                .build();
        autoGenerator.packageInfo(pc);

        StrategyConfig sc = new StrategyConfig.Builder()
                //去除table前缀
                .addTablePrefix("tb_")
                //需要生成的表
                .addInclude(Arrays.asList("tb_manage_user","tb_manage_role","tb_manage_menu"))
                //实体配置
                .entityBuilder().columnNaming(NamingStrategy.underline_to_camel).idType(IdType.AUTO)
                //service配置
                .serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImpl")
//mapper配置
.mapperBuilder().enableBaseResultMap()
                .build();
        autoGenerator.strategy(sc);
		//执行
        autoGenerator.execute();
    }
}

你可能感兴趣的:(mybatis,java)