日期格式化查询的区别:
selectSql.append(" AND DATE_FORMAT(o.createDate,\'%Y-%m-%d\') = :createDate");//单引号 countSql.append(" AND DATE_FORMAT(o.create_date,\"%Y-%m-%d\") = '" + DateUtils.date2String(pageRequest.getCreateDate(), DateUtils.ymd) + "'");
if(pageRequest.getCreateDate() != null){ query.setParameter("createDate", DateUtils.date2String(pageRequest.getCreateDate(), DateUtils.ymd)); }
模糊查询:
if(StringUtils.isNotBlank(pageRequest.getParkName())){ selectSql.append(" AND p.parkName like :parkName "); countSql.append(" and p.park_name like '%" + pageRequest.getParkName() + "%'"); } if (StringUtils.isNotBlank(pageRequest.getParkName())) { query.setParameter("parkName", "%" + pageRequest.getParkName() + "%"); //里面没有单引号 }