其他分享
首页 > 其他分享> > ibaits动态查询

ibaits动态查询

作者:互联网

直接分析:

1、动态查询sql语句为:

 <select id ="getMemberShipCard"  parameterClass ="hashMap" resultClass="membershipCard" >  
              select * from t_membershipcard  
          <dynamic  prepend ="WHERE" >  
          <!--  isPropertyAvailable判断属性是否有效  -->  
             <isPropertyAvailable  property ="slave_user" >  
               <isNotEmpty  property ="slave_user" >  
                  slave_user = #slave_user#  
               </isNotEmpty >  
             </isPropertyAvailable >
             <isPropertyAvailable property="cardNo">
                 <isNotEmpty property="cardNo">
                     and cardNo=#cardNo#
                 </isNotEmpty>
             </isPropertyAvailable>
             
               <isPropertyAvailable property="realname">
                 <isNotEmpty property="realname">
                     and realname like concat('%', #realname#, '%')
                 </isNotEmpty>
             </isPropertyAvailable>
             
              <isPropertyAvailable property="beforeTime">
                 <isNotEmpty property="beforeTime">
                     and <![CDATA[joinTime >= #beforeTime#]]>
                 </isNotEmpty>
             </isPropertyAvailable>
             
              <isPropertyAvailable property="afterTime">
                 <isNotEmpty property="afterTime">
                     and <![CDATA[joinTime <= #afterTime#]]>
                 </isNotEmpty>
             </isPropertyAvailable>
     
           </dynamic >  
         </select >

DAO层调用代码为:

@SuppressWarnings("unchecked")
    public List<MembershipCard> getMscList(MembershipCard card){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("realname", card.getRealname());
        map.put("beforeTime", card.getBeforeTime());
        map.put("afterTime", card.getAfterTime());
        map.put("cardNo", card.getCardNo());
        map.put("slave_user", card.getSlave_user());
        return sqlMapClient.queryForList("MembershipCardDAO.getMemberShipCard", map);
    }



标签:map,slave,ibaits,cardNo,查询,user,put,动态,card
来源: https://blog.51cto.com/binghe001/2928341