자바 iBATIS는 (오류의 문제를 해결 목록이 비어) 목록 유형 매개 변수를 사용하여

자바 iBATIS는 (오류의 문제를 해결 목록이 비어) 목록 유형 매개 변수를 사용하여

 

사용 또는 아닌, 예를 들어 여기에, 관련 데이터를 얻을 수있는 키워드의 쿼리시 (항목을 제외하는)에 필요

 

참조 목록으로 1. 직접 사용

다오 방법 정의 층 : 패키지 형식 매개 변수 목록

	/ ** 
	 * 정보 시스템의 채널을 기존의 현재 체크 아웃 
	 , 다른 지역의 정보에 액세스 제외하는 데 사용 * 제도적 매개 변수에 대한 예약 @param areaCode 번호를 
	 * @return 
	 * @throws IMException 
	 * / 
	공개 목록을 <ChannelPojo> queryAllChannels (문자열 areaCode) {IMException가 발생 

		; 일람 <문자열> = 새로운 새 exceptChannelList ArrayList를 <문자열> () 
		IF (StringUtils.isNotBlank (areaCode가 &&) "820 200".equals (areaCode이다)이다) { 
			exceptChannelList.add ( "10"); 
			exceptChannelList.add ( "을 ") (20)는 
		&&}는 다른 IF는 (StringUtils.isNotBlank (areaCode 임)"830300 ".equals (areaCode이다)) { 
			exceptChannelList.add는 ("21 인 "); 
			exceptChannelList.add ("22 인 "); 
			exceptChannelList.add ("23 "인 ) 
			exceptChannelList.( "25")를 추가;
		}
		logger.info ( "Demo.queryAllChannels, 매개 변수 areaCode 값은 :"+ areaCode); 
		logger.info ( "Demo.queryAllChannels, exceptChannelList입니다 :"+ exceptChannelList); 
		
		st.queryForList ( "kpiRptum.queryAllChannels", exceptChannelList)을 반환; 
	}
	

 

정의하는 SQLMaps, 매개 변수 정보를 추출 반복

기본 SQL 조각 :

<대하여 반복 오픈 = "("근접 = ")"함께 = "">
       <! [CDATA [#exceptChannelList [] #]]>
</ 반복 처리>

<SELECT ID = "queryAllChannels"의 parameterClass = "java.util.List가"resultClass를 = "com.imodule.report.dao.pojo.ChannelPojo"> 
	<! [CDATA [ 
		선택 
			channelcode 같은 codevalue 
			channelCfname 같은 이름 
			channelCsmpname로서 smpname 
			, channelEname로 () ','(engname 교환) 트림 
		에서 
			t_codedef 
		1 = 1 여기서 
	]> 
		및하지 codevalue 
		> ","<대하여 반복 오픈 = "("근접 = ")"함께 = 
		 	 <! [CDATA [   
             	 	  #exceptChannelList [] # 
              	       ]]> 
              </ 반복 처리> 
    
         
       <!  [CDATA [ 
		codevalue ASC별로 순서 
	]]> 
</ 선택>

  

 

2使用Map作为入参,将List对象存入Map集合中  (建议使用此方式,可避免当传入的List对象为空时而报错)

Dao层方法的定义: 封装Map类型参数

    /**
	 * 查询出目前系统已有的渠道信息
	 * @param areaCode 预留机构号参数,用于排除不同地区的渠道信息
	 * @return
	 * @throws IMException
	 */
	public List<ChannelPojo> queryAllChannels(String areaCode) throws IMException{
		Map<String, Object> map = new HashMap<String, Object>();
		List<String> 	exceptChannelList  = new ArrayList<String>();
		if(StringUtils.isNotBlank(areaCode) && "820200".equals(areaCode)){
			exceptChannelList.add("10");
			exceptChannelList.add("20");
		}else if(StringUtils.isNotBlank(areaCode) && "830300".equals(areaCode)){
			exceptChannelList.add("21");
			exceptChannelList.add("22");
			exceptChannelList.add("23");
			exceptChannelList.add("25");
		}
		map.put("exceptChannelList", exceptChannelList);
		logger.info("Demo.queryAllChannels,Parameter areaCode value is:"+areaCode);
		logger.info("Demo.queryAllChannels,exceptChannelList is:"+ exceptChannelList);
		
		return st.queryForList("kpiRptum.queryAllChannels",map);
	}

  

SqlMap的定义,迭代取出参数信息

主要sql片段:

<isPropertyAvailable property="exceptChannelList">
  <isNotEmpty property="exceptChannelList">
    and codevalue not in
    <iterate property="exceptChannelList" open="(" close=")" conjunction=",">
      <![CDATA[
        #exceptChannelList[]#
      ]]>
    </iterate>
  </isNotEmpty>

  <isEmpty property="exceptChannelList">
    <![CDATA[ and 1=1 ]]>
  </isEmpty>
</isPropertyAvailable>

<select id="queryAllChannels"  parameterClass="java.util.Map" resultClass="com.imodule.report.dao.pojo.ChannelPojo">
		<![CDATA[
			select 
				codevalue as channelcode
				,name as channelCfname
				,smpname as channelCsmpname
				,trim(replace(engname,' ','')) as channelEname
			from 
				t_codedef 
			where = 1=1
		]]>
		<isPropertyAvailable  property="exceptChannelList">
   			<isNotEmpty property="exceptChannelList">
				and codevalue not in 
			 	<iterate property="exceptChannelList"  open="(" close=")" conjunction=",">
			 		 <![CDATA[  
              	 		#exceptChannelList[]#
               		 ]]>
             	</iterate> 
        	</isNotEmpty>
        
    		<isEmpty property="exceptChannelList">
      	  		<![CDATA[ and  1=1 ]]>
    		</isEmpty>
	    </isPropertyAvailable>
          
        <![CDATA[  
			order by codevalue asc
		]]>
	</select>
	

  

추천

출처www.cnblogs.com/DFX339/p/12084719.html