2015-04-06 40 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>