We were happy with how we build dynamic SQL using above approach for a while. It works as expected and it is rather easy to maintain SQL statements. However, our features list are always change (and I guess you also face the problem like us, do you?). We are asked to build more flexible query statement, also controls the flow in SQL scripts not only with #if or #foreach. It is time we look for another solution of using script in our SQL statement and it is luckily we found MyBatis-Velocity project. Good things for us are we have experience with Velocity before, and it seems this project fit to our needs, the bad things is the author give only the short introduction how to use Velocity scripting engine in Velocity, also he did not instruct how we use velocity in Spring base application. After several trial and writing some unit tests and debug what are fails, I am delighted to share way how we use Velocity engine in Mybatis, Spring based application.