springboot 集成JFinal ActiveRecord

  • Post author:
  • Post category:其他




springboot 集成JFinal ActiveRecord

下面是JfinalActiveRecordPluginConfig 文件:

import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfuso.model._MappingKit;
import com.jfuso.utils.CommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program:jfuso
 * @ClassName:JfinalActiveRecordPluginConfig
 * @author:大神饶命
 * @Description: TODO springboot集成JFinal ActiveRecord
 * @Version 1.0
 **/
@Configuration
public class JfinalActiveRecordPluginConfig {

    /**
     * logger
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(JfinalActiveRecordPluginConfig.class);

    @Value("${spring.datasource.driverClassName}")
    private String driverClassName;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;
    @Value("${spring.datasource.url}")
    private String url;
    @Value("${jfinal.arp.show-sql}")
    private boolean showSql;
    @Value("${jfinal.arp.devMode}")
    private boolean devMode;

    @Bean
    public ActiveRecordPlugin initActiveRecordPlugin() {
        // 配置druid数据库连接池插件
        DruidPlugin druidPlugin = new DruidPlugin(url, username, password, driverClassName);
        // 配置ActiveRecord插件
        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        arp.setShowSql(showSql);
        arp.setDevMode(devMode);

        // 所有映射在 MappingKit 中自动化搞定
        _MappingKit.mapping(arp);

        // 开启插件
        druidPlugin.start();
        arp.start();
        LOGGER.info("JfinalActiveRecordPlugin Start Successful");

        return arp;
    }
}



版权声明:本文为maxufei6原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。