按条件检索hql语句

按条件模糊检索的hql语句拼装

public List<TuserN1> searchUser(String userName, String userTrueName,
			String time, String type, String jibie, String stat) {
		String hql = "from TuserN1 where 1=1";
		if (null != userName && !"".equals(userName)) {
			hql += " and userName like '%" + userName + "%' ";
		}
		if (null != userTrueName && !"".equals(userTrueName)) {
			hql += " and trueName like '%" + userTrueName + "%' ";
		}
		if (null != time && !"".equals(time)) {
			hql += " and time >=to_date( '"
					+ time
					+ " 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and time <=to_date( '"
					+ time + " 23:59:59', 'yyyy-mm-dd hh24:mi:ss')";
		}
		if (null != type && !"".equals(type)) {
			Long  ss=	Long.decode(type);
			hql += " and userType =" + ss;
		}
		if (null != jibie && !"".equals(jibie)) {
			Long  ji=Long.decode(jibie);
			hql += " and userLevel =" + ji;
		}
		if (null != stat && !"".equals(stat)) {
			Long  sstat=Long.decode(stat);
			hql += " and userState =" + sstat;
		}
		return getSession().createQuery(hql).list();
	}

留下,以备不时之需 奋斗


你可能感兴趣的:(按条件检索hql语句)