赞
踩
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>3.5.1</version>
- </dependency>
- <dependency>
- <groupId>com.microsoft.sqlserver</groupId>
- <artifactId>sqljdbc4</artifactId>
- <version>4.0</version>
- </dependency>
- package com.example.demo;
-
- import com.baomidou.mybatisplus.generator.FastAutoGenerator;
- import com.baomidou.mybatisplus.generator.config.OutputFile;
- import java.util.Collections;
-
-
- /**
- * <dependency>
- * <groupId>com.baomidou</groupId>
- * <artifactId>mybatis-plus-generator</artifactId>
- * <version>3.5.1</version>
- * </dependency>
- *
- * <dependency>
- * <groupId>org.apache.velocity</groupId>
- * <artifactId>velocity-engine-core</artifactId>
- * <version>2.3</version>
- * </dependency>
- *
- * 使用之前先导入依赖
- */
-
- public class Main {
- public static void main(String[] args) {
- // 数据库配置
- // 192.168.2.13:数据库地址
- // 1433:数据库端口
- // aaa:数据库名字
- String url = "jdbc:sqlserver://192.168.2.13:1433;DatabaseName=aaa";
- // 数据库账户和密码
- String username = "sa";
- String password = "";
- // 作者名字
- String author = "wjdsg";
- // 包信息
- String packageName = "com.example.demo";
- // 表名字,多张表,逗号隔开
- String[] tables = {"aaa_user"};
- // 本项目路径
- String projectPath = System.getProperty("user.dir");
- // 包绝对路径
- String outputDir =projectPath+"/src/main/java";
- // xml文件路径
- String outputDirMapper = projectPath+"/src/main/resources/mapper";
- FastAutoGenerator
- .create(url,username, password)
- .globalConfig(builder -> {
- builder.author(author) // 设置作者
- // .enableSwagger() // 开启 swagger 模式
- .fileOverride() // 覆盖已生成文件
- .outputDir(outputDir); // 指定输出目录
- })
- .packageConfig(builder -> {
- builder.parent(packageName)// 设置父包名
- // .moduleName("system") // 设置父包模块名
-
- .pathInfo(Collections.singletonMap(OutputFile.mapperXml, outputDirMapper)); // 设置mapperXml生成路径。注释不生成xml
- })
- .strategyConfig(builder -> {
- builder.addInclude(tables); // 设置需要生成的表名
- // .addTablePrefix("t_", "c_"); // 设置过滤表前缀
- })
- // .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
- .execute();
-
- }
-
-
- }
- spring:
- datasource:
- driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
- url: jdbc:sqlserver://192.168.2.13:1433;DatabaseName=aaa
- username: sa
- password:
- mybatis-plus:
- mapper-locations: classpath:mybatis/mapper/*Mapper.xml
- global-config:
- db-config:
- id-type: auto
- configuration:
- map-underscore-to-camel-case: true
- cache-enabled: false
- mapUnderscoreToCamelCase: true
- log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。