mybatis~中分页,带条件查询

<select id="selectAllAndByproduct_line" parameterType="hashmap" resultMap="ExtendResultMap" >
  	SELECT  t.id tid,t.name tname,p.*  
  		FROM project_template t INNER JOIN project_project p ON p.template_id = t.id 
where p.state=1 
<if test="lineId!=null and lineId!=''"> and p.product_line in
   <foreach item="item" index="index" collection="lineId" open="(" separator="," close=")"> 
       #{item}
   </foreach> 
</if> 
<if test="lineIdChild!=null and lineIdChild!=''">
   and p.child_product_line in 
  <foreach item="item" index="index" collection="lineIdChild" open="(" separator="," close=")">
     #{item} 
  </foreach> 
</if> 
<if test="name!=null and name!=''"> 
   and p.name LIKE '%'+#{name}+'%'
 </if> order by p.id </select>




		 Map<String, Object> paramMap =new HashMap<String, Object>();
		List<Integer> lineIdList=new ArrayList<Integer>();//定义产品线id集合
		List<Integer> lineIdChildList=new ArrayList<Integer>();//定义子线id集合
		
		//获取产品线指定的id-点击对应的产品线获取的id
		String pageNum=request.getParameter("pageNum");//当前页
		String pageSize=request.getParameter("pageSize");//页数量
		String lineIdName =request.getParameter("lineId");//获取产品线id字符串
		String lineIdChildName =request.getParameter("lineIdChild");//获取子线id,并拆分为数组
		String reachName=new String(((request.getParameter("reachName")==null||"".equals(request.getParameter("reachName")))?"":request.getParameter("reachName")).getBytes("iso-8859-1"),"utf-8");
		System.out.println("当前页"+pageNum+" 页数量"+pageSize+" 产品线id为:"+lineIdName+" 子线id为:"+lineIdChildName+" 搜索的名称为:"+reachName);
		
		//产品线id
		if(lineIdName!=null && !"".equals(lineIdName))
		{
			String lineId [] =lineIdName.split(",");//将产品线id字符串拆分为数组
			for (int i = 0; i < lineId.length; i++) 
			{
				System.out.println("异步显示产品线的id为:"+lineId[i]);
				lineIdList.add(Integer.parseInt(lineId[i]));//将产品线id放到产品线集合中
			}
			paramMap.put("lineId",lineIdList);//传递的是产品线id集合
		}
		else 
		{
			paramMap.put("lineId",null);//传递的是产品线id为空
		}
		//子线id
		if(lineIdChildName!=null&&!"".equals(lineIdChildName))
		{
			String lineIdChild []=lineIdChildName.split(",");//将子线id字符串拆分为数组
			for (int i = 0; i < lineIdChild.length; i++) 
			{
				lineIdChildList.add(Integer.parseInt(lineIdChild[i]));////将子线id房到集合中
			}
			paramMap.put("lineIdChild",lineIdChildList);//传递的是子线id集合
		}
		else 
		{
			paramMap.put("lineIdChild",null);//传递的是子线id为空
		}
		//分页中
		if(pageSize!=null&&!pageSize.equals(""))
		{
			if(pageNum!=null&&!pageNum.equals(""))
			{
				Integer exterNum = (Integer.parseInt(pageNum)-1)*Integer.parseInt(pageSize);
				paramMap.put("exterNum", exterNum);
			}else{
				paramMap.put("exterNum", 0);
			}
		}
		else
		{
			pageSize="5";//默认页面数量为5个
			if(pageNum!=null&&!pageNum.equals(""))
			{
				Integer exterNum = (Integer.parseInt(pageNum)-1)*Integer.parseInt(pageSize);
				paramMap.put("exterNum", exterNum);
			}else{
				paramMap.put("exterNum", 0);
			}
		}
		paramMap.put("pageSize", pageSize);
		paramMap.put("name", reachName);
		//获取全部的查询信息集合
		List<ProjectProjectExpandTwo> ProjectProjectExpandTwoList= projectService.selectAllAndByproduct_line(paramMap);
		Integer countnum=ProjectProjectExpandTwoList.size();//将总数传递到页面
		request.setAttribute("countnum", countnum);//将查询的总页数放到界面上
		//获取分页后的全部的查询信息集合
		List<ProjectProjectExpandTwo> ProjectProjectExpandTwoListFY= projectService.selectAllAndByproduct_lineFY(paramMap);

猜你喜欢

转载自1049097489.iteye.com/blog/2323511