|
@@ -0,0 +1,71 @@
|
|
|
+/**
|
|
|
+ * Copyright (c) 2011-2016, hubin (jobob@qq.com).
|
|
|
+ *
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
+ * use this file except in compliance with the License. You may obtain a copy of
|
|
|
+ * the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
+ * License for the specific language governing permissions and limitations under
|
|
|
+ * the License.
|
|
|
+ */
|
|
|
+package com.baomidou.mybatisplus.test.generator;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.generator.MybatisPlusGenerator;
|
|
|
+import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
|
|
+import com.baomidou.mybatisplus.generator.config.PackageConfig;
|
|
|
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
|
|
+import com.baomidou.mybatisplus.generator.config.rules.DbType;
|
|
|
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 代码生成器演示
|
|
|
+ * </p>
|
|
|
+ * @author hubin
|
|
|
+ * @date 2016-12-01
|
|
|
+ */
|
|
|
+public class MysqlGenerator {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * <p>
|
|
|
+ * MySQL 生成演示
|
|
|
+ * </p>
|
|
|
+ */
|
|
|
+ public static void main(String[] args) {
|
|
|
+ MybatisPlusGenerator mpg = new MybatisPlusGenerator();
|
|
|
+ mpg.setOutputDir("D://");
|
|
|
+ mpg.setFileOverride(true);
|
|
|
+ mpg.setActiveRecord(true);
|
|
|
+ mpg.setEnableCache(false);
|
|
|
+ mpg.setAuthor("Yanghu");
|
|
|
+
|
|
|
+ // 数据源配置
|
|
|
+ DataSourceConfig dsc = new DataSourceConfig();
|
|
|
+ dsc.setDbType(DbType.MYSQL);
|
|
|
+ dsc.setDriverName("com.mysql.jdbc.Driver");
|
|
|
+ dsc.setUsername("root");
|
|
|
+ dsc.setPassword("521");
|
|
|
+ dsc.setUrl("jdbc:mysql://127.0.0.1:3306/mybatis-plus?characterEncoding=utf8");
|
|
|
+ mpg.setDataSource(dsc);
|
|
|
+
|
|
|
+ // 策略配置
|
|
|
+ StrategyConfig strategy = new StrategyConfig();
|
|
|
+ strategy.setTablePrefix("bmd_");
|
|
|
+ strategy.setNaming(NamingStrategy.remove_prefix_and_camel);
|
|
|
+ mpg.setStrategy(strategy);
|
|
|
+
|
|
|
+ // 包配置
|
|
|
+ PackageConfig pc = new PackageConfig();
|
|
|
+ pc.setModuleName("test");
|
|
|
+ mpg.setPackageInfo(pc);
|
|
|
+
|
|
|
+ // 执行生成
|
|
|
+ mpg.execute();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|