use of com.jfinal.plugin.activerecord.dialect.MysqlDialect in project my_curd by qinyou.
the class AppConfig method configPlugin.
@Override
public void configPlugin(Plugins me) {
DruidPlugin dbPlugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password"));
// druid 监控
dbPlugin.addFilter(new StatFilter());
WallFilter wall = new WallFilter();
wall.setDbType("mysql");
dbPlugin.addFilter(wall);
ActiveRecordPlugin arp = new ActiveRecordPlugin(dbPlugin);
arp.setShowSql(PropKit.getBoolean("devMode"));
arp.setDialect(new MysqlDialect());
MappingKit.mapping(arp);
me.add(dbPlugin);
me.add(arp);
}
use of com.jfinal.plugin.activerecord.dialect.MysqlDialect in project fruit-manage by liuzhaozhao.
the class GeneratorDemo method main.
public static void main(String[] args) {
// base model 所使用的包名
// model 所使用的包名 (MappingKit 默认使用的包名)
String modelPackageName = "com.fruit.manage.model";
String baseModelPackageName = modelPackageName + ".base";
// base model 文件保存路径
String baseModelOutputDir = PathKit.getWebRootPath() + "/src/main/java/" + (baseModelPackageName.replaceAll("\\.", "/"));
// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
String modelOutputDir = baseModelOutputDir + "/..";
// 创建生成器
DataSource dataSource = getDataSource();
Generator gernerator = new Generator(dataSource, baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
// MetaBuilder metaBuilder = new MyMetaBuilder(dataSource,"game_account", "game_8868", "game_money");
// gernerator.setMetaBuilder(metaBuilder);
// 设置数据库方言
gernerator.setDialect(new MysqlDialect());
// 添加不需要生成的表名
String tables = "old-b_classify";
gernerator.addExcludedTable(tables.split(","));
// 设置是否在 Model 中生成 dao 对象
gernerator.setGenerateDaoInModel(true);
// 设置是否生成字典文件
gernerator.setGenerateDataDictionary(false);
// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
gernerator.setRemovedTableNamePrefixes("b_", "a_");
// 生成
gernerator.generate();
}
use of com.jfinal.plugin.activerecord.dialect.MysqlDialect in project jfinal by jfinal.
the class Config method createBrokenConfig.
/**
* Create broken config for DbKit.brokenConfig = Config.createBrokenConfig();
*/
static Config createBrokenConfig() {
Config ret = new Config();
ret.dialect = new MysqlDialect();
ret.showSql = false;
ret.devMode = false;
ret.transactionLevel = DbKit.DEFAULT_TRANSACTION_LEVEL;
ret.containerFactory = IContainerFactory.defaultContainerFactory;
ret.cache = new EhCache();
return ret;
}
use of com.jfinal.plugin.activerecord.dialect.MysqlDialect in project jfinal by jfinal.
the class _Generator method main.
public static void main(String[] args) {
// model 所使用的包名 (MappingKit 默认使用的包名)
String modelPackageName = "com.jfinal.common.model";
// base model 所使用的包名
String baseModelPackageName = modelPackageName + ".base";
// base model 文件保存路径
String baseModelOutputDir = System.getProperty("user.dir") + "/src/main/java/" + baseModelPackageName.replace('.', '/');
// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
String modelOutputDir = baseModelOutputDir + "/..";
System.out.println("输出路径:" + baseModelOutputDir);
// 创建生成器
Generator gen = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
// 设置数据库方言
gen.setDialect(new MysqlDialect());
// 设置是否生成字段备注
gen.setGenerateRemarks(true);
// 添加不需要生成的表名
for (String table : excludedTable) {
gen.addExcludedTable(table.trim());
}
// 设置是否在 Model 中生成 dao 对象
gen.setGenerateDaoInModel(false);
// 设置是否生成字典文件
gen.setGenerateDataDictionary(false);
// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
// gernerator.setRemovedTableNamePrefixes("t_");
// 将 mysql 8 以及其它原因之下生成 jdk 8 日期类型映射为 java.util.Date,便于兼容老项目,也便于习惯使用 java.util.Date 的同学
TypeMapping tm = new TypeMapping();
tm.addMapping(LocalDateTime.class, Date.class);
tm.addMapping(LocalDate.class, Date.class);
// tm.addMapping(LocalTime.class, LocalTime.class); // LocalTime 暂时不变
gen.setTypeMapping(tm);
// 生成
gen.generate();
}
use of com.jfinal.plugin.activerecord.dialect.MysqlDialect in project my_curd by qinyou.
the class SchemaInfoUtil method main.
public static void main(String[] args) {
// 注意 InformationSchema=true
DruidPlugin dp = new DruidPlugin("jdbc:mysql://127.0.0.1/my_curd?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useInformationSchema=true", "root", "123456");
dp.start();
Dialect mysqlDialect = new MysqlDialect();
SchemaInfoUtil util = new SchemaInfoUtil(mysqlDialect, dp.getDataSource());
List<Table> tables = util.getAllTableInfo(true);
DbKit.getConfig().getDialect();
DbKit.getConfig().getDataSource();
System.out.println(JsonKit.toJson(tables));
}
Aggregations