mybatis~ middle page, with conditional query

<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>();//Define product line id collection
		List<Integer> lineIdChildList=new ArrayList<Integer>();//Define the sub-line id collection
		
		//Get the id specified by the product line - click the id obtained by the corresponding product line
		String pageNum=request.getParameter("pageNum");//Current page
		String pageSize=request.getParameter("pageSize");//页数量
		String lineIdName =request.getParameter("lineId");//Get the product line id string
		String lineIdChildName =request.getParameter("lineIdChild");//Get the sub-line id and split it into an array
		String reachName=new String(((request.getParameter("reachName")==null||"".equals(request.getParameter("reachName")))?"":request.getParameter("reachName")).getBytes("iso-8859-1"),"utf-8");
		System.out.println("current page"+pageNum+" number of pages"+pageSize+" product line id:"+lineIdName+" sub-line id:"+lineIdChildName+" search name:"+reachName);
		
		// product line id
		if(lineIdName!=null && !"".equals(lineIdName))
		{
			String lineId [] =lineIdName.split(",");//Split the product line id string into an array
			for (int i = 0; i < lineId.length; i++)
			{
				System.out.println("Asynchronously display the id of the product line: "+lineId[i]);
				lineIdList.add(Integer.parseInt(lineId[i]));//Put the product line id into the product line collection
			}
			paramMap.put("lineId",lineIdList);//The product line id collection is passed
		}
		else
		{
			paramMap.put("lineId",null);//The product line id passed is empty
		}
		//subline id
		if(lineIdChildName!=null&&!"".equals(lineIdChildName))
		{
			String lineIdChild []=lineIdChildName.split(",");//Split the sub-line id string into an array
			for (int i = 0; i < lineIdChild.length; i++)
			{
				lineIdChildList.add(Integer.parseInt(lineIdChild[i]));////Add the sub-line id to the collection
			}
			paramMap.put("lineIdChild",lineIdChildList);//Passes the set of sub-line ids
		}
		else
		{
			paramMap.put("lineIdChild",null);//The sub-line id passed is empty
		}
		// in paging
		if(pageSize!=null&&!pageSize.equals(""))
		{
			if(pageNum!=null&&!pageNum.equals(""))
			{
				extern Integer = (Integer.parseInt(pageNum)-1)*Integer.parseInt(pageSize);
				paramMap.put("external", externalNum);
			}else{
				paramMap.put("external", 0);
			}
		}
		else
		{
			pageSize="5";//The default number of pages is 5
			if(pageNum!=null&&!pageNum.equals(""))
			{
				extern Integer = (Integer.parseInt(pageNum)-1)*Integer.parseInt(pageSize);
				paramMap.put("external", externalNum);
			}else{
				paramMap.put("external", 0);
			}
		}
		paramMap.put("pageSize", pageSize);
		paramMap.put("name", reachName);
		//Get all the query information collection
		List<ProjectProjectExpandTwo> ProjectProjectExpandTwoList= projectService.selectAllAndByproduct_line(paramMap);
		Integer countnum=ProjectProjectExpandTwoList.size();//Pass the total number to the page
		request.setAttribute("countnum", countnum);//Put the total number of pages in the query on the interface
		//Get all the query information collection after paging
		List<ProjectProjectExpandTwo> ProjectProjectExpandTwoListFY= projectService.selectAllAndByproduct_lineFY(paramMap);

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327063592&siteId=291194637