Class TemplateFilePathProvider

java.lang.Object
org.mybatis.scripting.thymeleaf.support.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);

 }
 
Version:
1.0.1
Author:
Kazuki Shimizu
  • Method Details

    • setCustomTemplateFilePathGenerator

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

      public static void setLanguageDriverConfig(ThymeleafLanguageDriverConfig languageDriverConfig)
      Set a configuration instance for ThymeleafLanguageDriver.

      By default, ThymeleafLanguageDriverConfig.newInstance() will used.

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

      Parameters:
      languageDriverConfig - A user defined ThymeleafLanguageDriverConfig
    • 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}.sql
      • com/example/mapper/NameMapper/NameMapper-{methodName}.sql (fallback using default database)
      • com/example/mapper/BaseMapper/BaseMapper-{methodName}-{databaseId}.sql (fallback using declaring class of method)
      • com/example/mapper/BaseMapper/BaseMapper-{methodName}.sql (fallback using declaring class of method and default database)

      Parameters:
      context - a context of SQL provider
      Returns:
      an SQL scripting string(template file path)
    • clearCache

      public static void clearCache()
      Clear cache.