2015-04-06 42 views
0

我在寻找mybatis标签,其中我可以动态地激发整个查询。我想在代码中构造完整的查询作为参数,并从mybatis中激发它。有什么办法,我可以这样做吗?Mybatis - 如何动态查询查询

+0

而不是构建在代码查询,您可以更好的MyBatis通过使用动态sql语句做同样的在所需的条件参数。 Mybatis对评估SQL查询中的条件提供了很好的支持。 – Shinchan 2015-04-18 03:38:25

回答

0

也许下面的例子可以给你一个别样的想法的那种由MyBatis的支持动态查询:

<select id="runQuery" resultType="map" parameterType="map" databaseId="mysql"> 
     SELECT 
     <if test="disableDistinct == false"> 
     DISTINCT 
     </if> 
     ${columnList} 
     FROM ${fromClause} 
     <if test="whereClause != null"> 
     WHERE ${whereClause} 
     </if> 
     <if test="orderClause != null"> 
     ORDER BY ${orderClause} 
     </if> 
     <if test="totalRows != null"> 
     LIMIT ${totalRows} 
     </if> 
    </select>