Class TemplateFilePathProvider
java.lang.Object
org.mybatis.scripting.freemarker.support.TemplateFilePathProvider
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.2.0
- Author:
- Kazuki Shimizu
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
The interface that implements a function for generating template file path. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clear cache.static String
provideSql
(org.apache.ibatis.builder.annotation.ProviderContext context) Provide an SQL scripting string(template file path).static void
Set custom implementation forTemplateFilePathProvider.PathGenerator
.static void
setLanguageDriverConfig
(FreeMarkerLanguageDriverConfig languageDriverConfig) Set a configuration instance forFreeMarkerLanguageDriver
.
-
Method Details
-
setCustomTemplateFilePathGenerator
public static void setCustomTemplateFilePathGenerator(TemplateFilePathProvider.PathGenerator pathGenerator) Set custom implementation forTemplateFilePathProvider.PathGenerator
.- Parameters:
pathGenerator
- a instance for generating a template file path
-
setLanguageDriverConfig
Set a configuration instance forFreeMarkerLanguageDriver
.By default,
FreeMarkerLanguageDriverConfig.newInstance()
will used.If you applied an user define
FreeMarkerLanguageDriverConfig
forFreeMarkerLanguageDriver
, please same instance to the this class.- Parameters:
languageDriverConfig
- A user definedFreeMarkerLanguageDriverConfig
-
provideSql
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)
- Parameters:
context
- a context of SQL provider- Returns:
- an SQL scripting string(template file path)
-
clearCache
public static void clearCache()Clear cache.
-