in using mybatis scripting language ,like freemarker ,usually define mapper interface like below:

interface SomeTypeMapper{
     @Select("some-type/findBySome.ftl") 
     List<SomeType> findByBySome();  
}

as you know , In @Select value style like namespace/method+'.ftl',it always has much more methods in mappers ,developer must write many of this style code for mybatis LanguageDriver to creating SqlSource, this style of Annotation is more common templated,think to add overload a method in LanguageDriver like below :

public interface LanguageDriver {
     SqlSource createSqlSource(Configuration configuration,Class<?> mapperType, Method mapperMethod, Class<?> parameterType);
}

to help find the sql templated styling ,current method in interface LanguageDriver is not friendly for annotation style by scripting sql template found! THANKS

Comment From: kazuki43zoo

I think you can resolve this with using the TemplateFilePathProvider.

  • mybatis-freemarker.properties
templateFile.pathProvider.includesMapperNameWhenSeparateDirectory = false

It find a template file from namespace/method+'.ftl' (e.g. /com/example/SampleMapper/findById.ftl) .

Comment From: stepjacky

@kazuki43zoo

-Not only this , the class TemplateFilePathProvider you provided is in fact a SqlProvider ,isn't it?

-Actually ,it just convert declaring a @Select Annotation to a @SelectProvider Annotation,I was always defined the common CURD operation of every POJO entity by this way ,but there usually has amount of other mapper methods need be load scripting file from some agreed path .

-I thought to create its SqlSource without declaring any Annotation to a method but use Mapper class and Mapper method to get it at LanguageDriver createSqlSource method from som called "The appointment is greater than configuration".

Comment From: kazuki43zoo

@stepjacky

Please refer to the previous discussion similar to this issue(#1492). In that discussion, we decided to not passed a source informations(e.g. statement id, mapper type and method, etc...) to the LanguageDriver.

@harawata Please comment if you have any supplements.

Comment From: stepjacky

LanguageDriver's task is to process an already loaded SQL script and I think it's better to keep this separation. @harawata @kazuki43zoo I dont think it is suitable for any scenes above ,and in xml sql source ,this statement is suitable,but annotation, because of xml sql source is configed by multi-way ,the property mapper location on configuration can clearly located mapper.xml file from variable way and without any other extra step,while annotationd mapper can't ,there has no way apart from adding sql annotation or sql provider annotation on a mapper method to locate the scripting template , so i think there need some way to do it , for every mapper method assign every scripting template location is troubled and unnecessary! in issue (https://github.com/mybatis/mybatis-3/pull/1492), give LanguageDriver method a context maybe a good idea!

Comment From: harawata

Hi @stepjacky ,

My English is not very good, so please let me clarify. You want to load some .ftl file without writing annotation on a method, is that correct?

Comment From: stepjacky

@harawata
It's almost my opinion. it make code more concision ,and if writing annotation use it , otherwise,use default action we previous discussed.

Comment From: harawata

Hi @stepjacky ,

Thank you for the clarification. When there is no annotation, MyBatis looks for a mapped statement loaded from XML mappers and LanguageDriver is not used in this process. There may be a way to achieve what you want, but using LanguageDriver is not the right approach.

Comment From: stepjacky

@harawata yes i agree with you ,may be in global configuration,may be in somewhere needed .thanks for focusing on it,and waiting for more idea! And i have viewed the source of mybatis about SqlSource building, it looks like just only in LanguageDriver to load scripting template source. hoping to more...

Comment From: harawata

As @kazuki43zoo and I explained, we don't plan to pass method related information to language driver at present.