Commit af53b9bf by stylefeng

代码生成增加对业务表的字段读取

parent c10717e8
package com.stylefeng.guns.core.template.engine.base;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.stylefeng.guns.core.template.config.*;
/**
......@@ -16,6 +17,7 @@ public class AbstractTemplateEngine {
protected DaoConfig daoConfig; //Dao配置
protected ServiceConfig serviceConfig; //Service配置
protected SqlConfig sqlConfig; //sql配置
protected TableInfo tableInfo; //表的信息
public void initConfig() {
if (this.contextConfig == null) {
......@@ -101,5 +103,13 @@ public class AbstractTemplateEngine {
public void setSqlConfig(SqlConfig sqlConfig) {
this.sqlConfig = sqlConfig;
}
public TableInfo getTableInfo() {
return tableInfo;
}
public void setTableInfo(TableInfo tableInfo) {
this.tableInfo = tableInfo;
}
}
......@@ -45,11 +45,12 @@ public abstract class GunsTemplateEngine extends AbstractTemplateEngine {
}
protected void configTemplate(Template template) {
template.binding("controller", super.getControllerConfig());
template.binding("context", super.getContextConfig());
template.binding("dao", super.getDaoConfig());
template.binding("service", super.getServiceConfig());
template.binding("controller", super.controllerConfig);
template.binding("context", super.contextConfig);
template.binding("dao", super.daoConfig);
template.binding("service", super.serviceConfig);
template.binding("sqls", super.sqlConfig);
template.binding("table",super.tableInfo);
}
protected void generateFile(String template, String filePath) {
......
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.stylefeng.guns.core.template.config.ContextConfig;
import com.stylefeng.guns.core.template.config.SqlConfig;
import com.stylefeng.guns.core.template.engine.SimpleTemplateEngine;
......@@ -12,6 +13,7 @@ import com.stylefeng.guns.core.template.engine.base.GunsTemplateEngine;
import com.stylefeng.guns.core.util.FileUtil;
import java.io.File;
import java.util.List;
/**
* 代码生成的抽象配置
......@@ -33,6 +35,8 @@ public abstract class AbstractGeneratorConfig {
PackageConfig packageConfig = new PackageConfig();
TableInfo tableInfo = null;
/**
* Guns代码生成器配置
*/
......@@ -99,6 +103,12 @@ public abstract class AbstractGeneratorConfig {
autoGenerator.setPackageInfo(packageConfig);
autoGenerator.execute();
destory();
//获取table信息,用于guns代码生成
List<TableInfo> tableInfoList = autoGenerator.getConfig().getTableInfoList();
if(tableInfoList != null && tableInfoList.size() > 0){
this.tableInfo = tableInfoList.get(0);
}
}
public void doGunsGeneration() {
......@@ -106,6 +116,7 @@ public abstract class AbstractGeneratorConfig {
gunsTemplateEngine.setContextConfig(contextConfig);
sqlConfig.setConnection(dataSourceConfig.getConn());
gunsTemplateEngine.setSqlConfig(sqlConfig);
gunsTemplateEngine.setTableInfo(tableInfo);
gunsTemplateEngine.start();
}
}
......@@ -13,7 +13,7 @@ public class GunsGeneratorConfig extends AbstractGeneratorConfig {
@Override
protected void globalConfig() {
globalConfig.setOutputDir("D:\\ideaSpace\\guns\\guns-admin\\src\\main\\java");
globalConfig.setOutputDir("/Users/stylefeng/work/ideaSpace/guns/guns-admin/src/main/java");
globalConfig.setFileOverride(true);
globalConfig.setEnableCache(false);
globalConfig.setBaseResultMap(true);
......@@ -34,7 +34,7 @@ public class GunsGeneratorConfig extends AbstractGeneratorConfig {
@Override
protected void strategyConfig() {
//strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀
strategyConfig.setInclude(new String[]{"my_order"});
strategyConfig.setInclude(new String[]{"bill"});
strategyConfig.setNaming(NamingStrategy.underline_to_camel);
}
......@@ -49,10 +49,10 @@ public class GunsGeneratorConfig extends AbstractGeneratorConfig {
@Override
protected void contextConfig() {
contextConfig.setBizChName("记账管理");
contextConfig.setBizEnName("order");
contextConfig.setBizEnName("bill");
contextConfig.setModuleName("system");
contextConfig.setProjectPath("D:\\ideaSpace\\guns\\guns-admin");
contextConfig.setEntityName("MyOrder");
contextConfig.setProjectPath("/Users/stylefeng/work/ideaSpace/guns/guns-admin");
contextConfig.setEntityName("Bill");
sqlConfig.setParentMenuName("系统管理");
/**
......
......@@ -14,7 +14,12 @@ var ${context.bizEnBigName} = {
${context.bizEnBigName}.initColumn = function () {
return [
{field: 'selectItem', radio: true},
{title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'}
<% for(item in table.fields!){ %>
<% if(itemLP.last != true){ %>
{title: '${item.comment}', field: '${item.propertyName}', visible: true, align: 'center', valign: 'middle'},
<% }else{ %>
{title: '${item.comment}', field: '${item.propertyName}', visible: true, align: 'center', valign: 'middle'}
<% }} %>
];
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment