Jdbc代码片断:使sql in子句中的记录数恒定

	private List<Long> toNormalizedList(List<Long> idList) {
		List<Long> newList = new ArrayList<Long>();
		newList.addAll(idList);
		for (int i = idList.size() + 1; i <= 100; i++) { // 填满100个,使得每个prepared
															// statement都有100参数,以充分利用sql缓存
			newList.add(idList.get(0));
		}
		return newList;
	}

相应的ibatis sql map:


	<select id="batchGet" parameterClass="list" resultClass="java.lang.Long">
		select distinct *
		from some_table
		where id in
		  <iterate open="(" close=")" conjunction=",">
  			 #[]#
  		  </iterate>
	</select>		

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.