Class TemplateFilePathProvider


public class TemplateFilePathProvider extends Object
The SQL provider class that return the SQL template file path.

IMPORTANT: This class required to use with mybatis 3.5.1+ and need to use with SQL provider annotation (such as SelectProvider as follow:

 package com.example.mapper;

 public interface BaseMapper<T> {

   @Options(useGeneratedKeys = true, keyProperty = "id")
   @InsertProvider(type = TemplateFilePathProvider.class)
   void insert(T entity);

   @UpdateProvider(type = TemplateFilePathProvider.class)
   void update(T entity);

   @DeleteProvider(type = TemplateFilePathProvider.class)
   void delete(T entity);

   @SelectProvider(type = TemplateFilePathProvider.class)
   T findById(Integer id);

 package com.example.mapper;

 public interface NameMapper extends BaseMapper {

   @SelectProvider(type = TemplateFilePathProvider.class)
   List<Name> findByConditions(NameConditions conditions);

Kazuki Shimizu
  • Method Details

    • setCustomTemplateFilePathGenerator

      public static void setCustomTemplateFilePathGenerator(TemplateFilePathProvider.PathGenerator pathGenerator)
      Set custom implementation for TemplateFilePathProvider.PathGenerator.
      pathGenerator - a instance for generating a template file path
    • setLanguageDriverConfig

      public static void setLanguageDriverConfig(FreeMarkerLanguageDriverConfig languageDriverConfig)
      Set a configuration instance for FreeMarkerLanguageDriver.

      By default, FreeMarkerLanguageDriverConfig.newInstance() will used.

      If you applied an user define FreeMarkerLanguageDriverConfig for FreeMarkerLanguageDriver, please same instance to the this class.

      languageDriverConfig - A user defined FreeMarkerLanguageDriverConfig
    • provideSql

      public static String provideSql(org.apache.ibatis.builder.annotation.ProviderContext context)
      Provide an SQL scripting string(template file path).

      By default implementation, a template file path resolve following format and priority order. If does not match all, it throw an exception that indicate not found a template file.

      • com/example/mapper/NameMapper/NameMapper-{methodName}-{databaseId}.ftl
      • com/example/mapper/NameMapper/NameMapper-{methodName}.ftl (fallback using default database)
      • com/example/mapper/BaseMapper/BaseMapper-{methodName}-{databaseId}.ftl (fallback using declaring class of method)
      • com/example/mapper/BaseMapper/BaseMapper-{methodName}.ftl (fallback using declaring class of method and default database)
      context - a context of SQL provider
      an SQL scripting string(template file path)
    • clearCache

      public static void clearCache()
      Clear cache.