IBATIS 的动态SQL语句拼接

 <select id="Analysis" resultClass="stationGroupInfo" parameterclass="hashtable">

      select     

    <dynamic>      

      <!--> 注意这里的$ 如果字符串直接拼接要用$,#默认会在字符串变量前面加引号的 -->      

      <isNotEmpty property="AnalysiStr">         $AnalysiStr$               </isNotEmpty>    

    </dynamic>      

     <!--> left join 2 个表 是这样写的  -->      

     from dbo.stationInfo  a left join categoryInfo  b  on a.categoryId = b.cId left join countryInfo c on a.countryId = c.cId

        <dynamic prepend="where">

           <isNotEmpty prepend="and" property="yearType">          

       $yearType$=#yearValue#

           </isNotEmpty>        

     <isNotEmpty prepend="and" property="categoryId">、

              categoryId=#categoryId#

           </isNotEmpty>

           <isNotEmpty prepend="and" property="countryId">

              countryId=#countryId#

           </isNotEmpty>

         </dynamic>      

     <dynamic>        

      <isNotEmpty property="GroupByStr">

               $GroupByStr$ order by Name asc

            </isNotEmpty>

         </dynamic>

  </select>

posted @ 2012-09-05 17:32  oftenlin  阅读(4449)  评论(0编辑  收藏  举报