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);
    }


你可能感兴趣的:(sql,map,HashMap,select,ibaits)