ibatis dynamic条件语句问题

ibatis 的dynamic这样写会有问题,如果有条件成立,出现where 后面会少一个and,这是因为ibatis的dynamic语句会默认把第一个条件成立的predend字段去掉,比如如果下面两个条件都成立,那么最终的语句会变成where status=status的值 and name=name的值,

where

<dynamic   prepend=" ">                       
                      <isNotEmpty   prepend="and"   property="status">  
                          status   =   #status#      
                      </isNotEmpty>  
                       
                      <isNotEmpty   prepend="and"   property="name">   
                          name   =   #name#      
                      </isNotEmpty>                   
                         
</dynamic>  

所以必须得写成

where

<dynamic   prepend="and">                       
                      <isNotEmpty   prepend="and"   property="status">  
                          status   =   #status#      
                      </isNotEmpty>  
                       
                      <isNotEmpty   prepend="and"   property="name">   
                          name   =   #name#      
                      </isNotEmpty>                   
                         
</dynamic

posted @ 2009-12-09 21:04  zhwj184  阅读(207)  评论(0编辑  收藏  举报