getSession().createCriteria()查询

@Override
	public List<Dynamic> findByMap(Map<String, String> map) {
		String page = map.get("page");
		String rows = map.get("rows");
		String sort = map.get("sort");
		String order = map.get("order");
		String startDate = map.get("startDate");
		String endDate = map.get("endDate");
		
		Criteria criteria = getSession().createCriteria(Dynamic.class);
		if(StringUtils.isNotEmpty(page) && StringUtils.isNotEmpty(rows)){
			criteria.setFirstResult((Integer.parseInt(page)-1)*Integer.parseInt(rows));
			criteria.setMaxResults(Integer.parseInt(rows));
			criteria.addOrder(Order.asc("focusNews"));
		}
		if(StringUtils.isNotBlank(sort)){
			if(order.equals("desc")){
				criteria.addOrder(Order.desc(sort));
			}else{
				criteria.addOrder(Order.asc(sort));
			}
		}
		if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)){
			String[] pattern = new String[]{
					"yyyy-MM","yyyyMM","yyyy/MM","yyyyMMdd","yyyy-MM-dd","yyyy/MM/dd",   
	                "yyyyMMddHHmmss",   "yyyy-MM-dd HH:mm:ss","yyyy/MM/dd HH:mm:ss"
	                };  
			try {
				criteria.add(Restrictions.between("createTime", DateUtils.parseDate(startDate, pattern),DateUtils.parseDate(endDate, pattern)));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return criteria.list();
	}

你可能感兴趣的:(getSession().createCriteria()查询)