Search in sources :

Example 1 with ClassPathSourceFactory

use of com.jfinal.template.source.ClassPathSourceFactory in project jboot by yangfuhai.

the class JbootServiceImplGenerator method generate.

public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate Service Impl ...");
    System.out.println("Service Impl Output Dir: " + outputDir);
    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", JavaKeyword.me);
    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
Also used : ClassPathSourceFactory(com.jfinal.template.source.ClassPathSourceFactory) TableMeta(com.jfinal.plugin.activerecord.generator.TableMeta) StrKit(com.jfinal.kit.StrKit) Engine(com.jfinal.template.Engine)

Example 2 with ClassPathSourceFactory

use of com.jfinal.template.source.ClassPathSourceFactory in project jboot by yangfuhai.

the class JbootServiceInterfaceGenerator method generate.

@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);
    Engine engine = Engine.create("forService");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);
    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
Also used : ClassPathSourceFactory(com.jfinal.template.source.ClassPathSourceFactory) TableMeta(com.jfinal.plugin.activerecord.generator.TableMeta) StrKit(com.jfinal.kit.StrKit) Engine(com.jfinal.template.Engine)

Example 3 with ClassPathSourceFactory

use of com.jfinal.template.source.ClassPathSourceFactory in project mica by lets-mica.

the class ActiveRecordConfiguration method activeRecordPlugin.

@Bean
public ActiveRecordPlugin activeRecordPlugin(IDataSourceProvider dataSourceProvider, Environment environment, ResourceLoader resourceLoader, MicaActiveRecordProperties properties, ObjectProvider<List<ActiveRecordPluginCustomizer>> arpCustomizerProvider) {
    String modelPackage = properties.getModelPackage();
    Assert.hasText(modelPackage, "mica.activerecord.model-package is blank.");
    ActiveRecordPlugin arp = new ActiveRecordPlugin(dataSourceProvider);
    arp.setDialect(properties.getDialect().getDialect());
    arp.setTransactionLevel(properties.getTransactionLevel().getLevel());
    arp.setShowSql(false);
    // 加载 sql 模板
    String[] sqlTemplates = properties.getSqlTemplates();
    if (StrKit.notBlank(sqlTemplates)) {
        Engine engine = arp.getEngine();
        engine.setBaseTemplatePath(properties.getBaseTemplatePath());
        engine.setSourceFactory(new ClassPathSourceFactory());
        Arrays.stream(sqlTemplates).forEach(arp::addSqlTemplate);
    }
    // 扫描和添加表映射
    if (properties.isAutoTableScan()) {
        scanTable(arp, environment, resourceLoader, modelPackage);
    }
    // arp 自定义配置 bean
    arpCustomizerProvider.ifAvailable(customizers -> customizers.forEach(customizer -> customizer.customize(arp)));
    arp.start();
    return arp;
}
Also used : Arrays(java.util.Arrays) Model(com.jfinal.plugin.activerecord.Model) ActiveRecordTxAspect(net.dreamlu.mica.activerecord.tx.ActiveRecordTxAspect) Value(org.springframework.beans.factory.annotation.Value) Engine(com.jfinal.template.Engine) ObjectProvider(org.springframework.beans.factory.ObjectProvider) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) DataSource(javax.sql.DataSource) SqlLogFilter(net.dreamlu.mica.activerecord.logger.SqlLogFilter) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ResourceLoader(org.springframework.core.io.ResourceLoader) ClassUtils(org.springframework.util.ClassUtils) DruidPlugin(com.jfinal.plugin.druid.DruidPlugin) ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) AnnotationUtils(org.springframework.core.annotation.AnnotationUtils) Set(java.util.Set) TableName(net.dreamlu.mica.activerecord.annotation.TableName) Configuration(org.springframework.context.annotation.Configuration) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ClassPathSourceFactory(com.jfinal.template.source.ClassPathSourceFactory) Environment(org.springframework.core.env.Environment) ActiveRecordPlugin(com.jfinal.plugin.activerecord.ActiveRecordPlugin) SpringDataSourceProvider(net.dreamlu.mica.activerecord.datasource.SpringDataSourceProvider) StrKit(com.jfinal.kit.StrKit) IDataSourceProvider(com.jfinal.plugin.activerecord.IDataSourceProvider) Bean(org.springframework.context.annotation.Bean) Assert(org.springframework.util.Assert) ClassPathSourceFactory(com.jfinal.template.source.ClassPathSourceFactory) ActiveRecordPlugin(com.jfinal.plugin.activerecord.ActiveRecordPlugin) Engine(com.jfinal.template.Engine) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with ClassPathSourceFactory

use of com.jfinal.template.source.ClassPathSourceFactory in project ieasy-server by baayso.

the class ViewConfig method jFinalViewResolver.

/**
 * Enjoy Template Engine(https://www.jfinal.com/doc/6-1)
 */
@Bean
public JFinalViewResolver jFinalViewResolver() {
    JFinalViewResolver jfr = new JFinalViewResolver();
    // setDevMode 配置放在最前面
    jfr.setDevMode(log.isDebugEnabled());
    // 使用 ClassPathSourceFactory 从 class path 与 jar 包中加载模板文件
    jfr.setSourceFactory(new ClassPathSourceFactory());
    // 在使用 ClassPathSourceFactory 时要使用 setBaseTemplatePath() 代替 jfr.setPrefix("/templates/")
    JFinalViewResolver.engine.setBaseTemplatePath("/templates/");
    jfr.setSuffix(".html");
    jfr.setContentType("text/html;charset=UTF-8");
    jfr.setOrder(0);
    jfr.addSharedFunction("common/layout.html");
    jfr.addSharedFunction("common/main.html");
    jfr.addSharedFunction("common/header.html");
    jfr.addSharedFunction("common/menu.html");
    jfr.addSharedFunction("common/footer.html");
    return jfr;
}
Also used : JFinalViewResolver(com.jfinal.template.ext.spring.JFinalViewResolver) ClassPathSourceFactory(com.jfinal.template.source.ClassPathSourceFactory) Bean(org.springframework.context.annotation.Bean)

Aggregations

ClassPathSourceFactory (com.jfinal.template.source.ClassPathSourceFactory)4 StrKit (com.jfinal.kit.StrKit)3 Engine (com.jfinal.template.Engine)3 TableMeta (com.jfinal.plugin.activerecord.generator.TableMeta)2 Bean (org.springframework.context.annotation.Bean)2 ActiveRecordPlugin (com.jfinal.plugin.activerecord.ActiveRecordPlugin)1 IDataSourceProvider (com.jfinal.plugin.activerecord.IDataSourceProvider)1 Model (com.jfinal.plugin.activerecord.Model)1 DruidPlugin (com.jfinal.plugin.druid.DruidPlugin)1 JFinalViewResolver (com.jfinal.template.ext.spring.JFinalViewResolver)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 DataSource (javax.sql.DataSource)1 Slf4j (lombok.extern.slf4j.Slf4j)1 TableName (net.dreamlu.mica.activerecord.annotation.TableName)1 SpringDataSourceProvider (net.dreamlu.mica.activerecord.datasource.SpringDataSourceProvider)1 SqlLogFilter (net.dreamlu.mica.activerecord.logger.SqlLogFilter)1 ActiveRecordTxAspect (net.dreamlu.mica.activerecord.tx.ActiveRecordTxAspect)1