java多条件模糊查询代码大概实现方法非where 1=1方法

/**
	 * 查询列表
	 * @return
	 */
	public String findJkjkMalfuncExperiencList()
	{
		
		StringBuilder hql =new StringBuilder("from JkjkMalfuncexperience ");
		 boolean b = true;
		 if(jkjkMalfunc!=null)
		 {
			 if(jkjkMalfunc.getExpid()!=null&&!"".equals(jkjkMalfunc.getExpid()))
				{
				 //判断是否有where存在
					b = this.hashWhere(hql,b);
					hql.append(" expid like '%"+jkjkMalfunc.getExpid()+"%'");
				}
			 if(jkjkMalfunc.getExptitle()!=null&&!"".equals(jkjkMalfunc.getExptitle()))
				{
					b = this.hashWhere(hql,b);
					hql.append(" exptitle like '%"+jkjkMalfunc.getExptitle()+"%'");
				}
			 System.out.println("测试语句:"+hql);
			 PageResultSet  pageResultList = jkjkMalfuncExperienceManager.findJkjkMalfuncList(currentPage,10,hql.toString());
				ActionContext.getContext().put("pageResultList", pageResultList);
		 }
		
		
		return SUCCESS;
	}
               //判断where是否存在方法	
	public boolean hashWhere(StringBuilder hql,boolean hashWhere)
	{
		
                               //where存在将返回false	
		if(hashWhere)
		{
			hql.append(" where ");
			hashWhere = false;
		}else
		{
			hql.append(" and ");
		}
		return hashWhere;
	}

 

你可能感兴趣的:(java功能)