|
|
|
@ -0,0 +1,68 @@
|
|
|
|
|
package com.wanman.springbootmybatis.Test;
|
|
|
|
|
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
|
|
|
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
|
import com.jfinal.plugin.redis.RedisPlugin;
|
|
|
|
|
import com.wanman.springbootmybatis.SpringBootMybatisApplication;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class TestJFinal {
|
|
|
|
|
|
|
|
|
|
public static void InitJFinal() {
|
|
|
|
|
PropKit.use("application.properties");
|
|
|
|
|
/**
|
|
|
|
|
* 配置插件
|
|
|
|
|
*/
|
|
|
|
|
String connectionTestQuery = "select 1";
|
|
|
|
|
// 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
|
|
|
|
|
int maxPoolSize = 10;
|
|
|
|
|
// 一个连接 idle 状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟
|
|
|
|
|
long idleTimeoutMs = 600000;
|
|
|
|
|
long maxLifetimeMs = 1800000;
|
|
|
|
|
// 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生 SQLException, 缺省:30秒
|
|
|
|
|
long connectionTimeoutMs = 30000;
|
|
|
|
|
|
|
|
|
|
HikariCpPlugin hp = new HikariCpPlugin(PropKit.get("spring.datasource.url"), PropKit.get("spring.datasource.username"),
|
|
|
|
|
PropKit.get("spring.datasource.password").trim(), PropKit.get("spring.datasource.driver-class-name"));
|
|
|
|
|
hp.setConnectionTestQuery(connectionTestQuery);
|
|
|
|
|
hp.setConnectionTimeout(connectionTimeoutMs);
|
|
|
|
|
hp.setIdleTimeout(idleTimeoutMs);
|
|
|
|
|
hp.setMaxLifetime(maxLifetimeMs);
|
|
|
|
|
hp.setMaximumPoolSize(maxPoolSize);
|
|
|
|
|
hp.start();
|
|
|
|
|
|
|
|
|
|
// 配置ActiveRecord插件
|
|
|
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin("master", hp);
|
|
|
|
|
arp.setDialect(new MysqlDialect());
|
|
|
|
|
|
|
|
|
|
//遍历sql目录下所有的sql文件
|
|
|
|
|
File sqlDir;
|
|
|
|
|
String basePath = SpringBootMybatisApplication.class.getClassLoader().getResource(".").getPath();
|
|
|
|
|
sqlDir = new File(basePath + "/Sql");
|
|
|
|
|
File[] sqlFiles = sqlDir.listFiles();
|
|
|
|
|
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
|
|
|
|
|
//只加载.sql文件
|
|
|
|
|
if (sqlFile.getName().indexOf(".sql") > 0) {
|
|
|
|
|
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//加载
|
|
|
|
|
arp.start();
|
|
|
|
|
// 用于缓存模块的redis服务
|
|
|
|
|
//RedisPlugin redis = new RedisPlugin("Redis", PropKit.get("redis_ip"), PropKit.getInt("redis_port"), 10 * 1000);
|
|
|
|
|
//启动redis组件
|
|
|
|
|
//redis.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
InitJFinal();
|
|
|
|
|
List<Record> list= Db.findAll("t_article");
|
|
|
|
|
System.out.println(list);
|
|
|
|
|
}
|
|
|
|
|
}
|