Sunday, March 8, 2015

FreeMarker plugin for MyBatis

Kostromin Igor has created a project to provide a FreeMarker plugin for MyBatis.

This is how a mapper looks like with FreeMarker:

@Lang(FreeMarkerLanguageDriver.class)
@Select("select * from names where id in (${ids?join(',')})")
List<Name> findNamesByIds(@Param("ids") List<Integer> ids);

You can also use FreeMarker templates this way:

@Lang(FreeMarkerLanguageDriver.class)
@Select("findName.ftl")
Name findName(@Param("n") String name);

Where findName.ft1 is:

SELECT *
FROM names
where firstName = <@p name="n"/>
See more and contribute at the project's page at Github

Enjoy!

No comments:

Post a Comment