【匯智學堂】mybatis參數傳入集合的處理方式

 

1.dao層接口

public interface projectDao {

    List<CountResultPO> getIndexProjectList(CountPO countPO);
}

2.封裝實體

public class CountPO {
    private static final long serialVersionUID = 1L;

    private List<BusProject> cityList = Lists.newArrayList();	
	
	//getter /setter
}

3.xml配置文件

<select id="getIndexProjectList" resultType="com.entity.CountResultPO">
	SELECT 
		b.amount,are.name as category,b.FD_CITY as cityId
	from (
		SELECT a.FD_CITY as FD_CITY,count(1) as amount from BUS_PROJECT a
	where a.del_flag = 0
	<if test="null != cityList and cityList.size > 0">
		AND a.fd_city in
		<foreach item="item" index="index" collection="cityList" open="(" separator="," close=")">
			#{item.fdCity}   //在BusProject實體中
		</foreach>
	</if>

	GROUP BY a.FD_CITY) b
	
	LEFT JOIN SYS_AREA are 
	
	on b.FD_CITY = are.id
</select>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章