java - How to use <foreach> statement in @SelectProvider class with MyBatis3 -
i trying use @selectprovider
create dynamic sql including use of tag foreach
in
clause. know how use using @select
annotation mapper.
the problem when translate sql sqlprovider seem use of tag directly not processed proxy invoke sqlprovider method sql.
here code example using @select
:
// imports... public interface mymapper { @select({"<script>", "select col_1, col_2", "from table_1", "where col_3 in", "<foreach item='item' index='index' collection='items'", "open='(' separator=',' close=')'>", "#{item}", "</foreach>", "</script>"}) hashmap<string, object> select(@param("items") string[] items); }
the code above works, when try use @selectprovider
doesn't works.
this code when use @selectprovider:
// imports... public interface mymapper { @selectprovider(type = mysqlprovider.class, method = "select") hashmap<string, object> select(@param("items") string[] items); } public class mysqlprovider { public string select() { sql sql = new sql(); sql.select("col_1"); sql.select("col_2"); sql.from("table_1"); sql.where("col_3 in" + "<foreach item='item' index='index' collection='items'" + "open='(' separator=',' close=')'>" + "#{item}" + "</foreach>"); return "<script>" + sql.tostring() + "</script>"; } }
when use mymapper
process sql ignore script
, foreach
statements.
could provide concrete solution including code?
Comments
Post a Comment