多个约束条件的查询

多个约束条件的查询_第1张图片


 public List getTodayData(String userId, String userName, String deptCode, String startTime, String endTime, boolean pagination) {
        String sql = "select userid,username,deptcode,deptname,to_char(logintime,'yyyy-MM-dd') as logintime from t_import_export_temp where 1=1";
        List paramList = new ArrayList();
        if (StringUtils.isNotBlank(userId)) {
            sql += " and userId=?";
            paramList.add(userId);
        }
        if (StringUtils.isNotBlank(userName)) {
            sql += (" and userName like ?");
            paramList.add("%" + userName + "%");
        }
        if (StringUtils.isNotBlank(deptCode)) {
            sql += " and deptCode=?";
            paramList.add(deptCode);
        }
        if (StringUtils.isNotBlank(startTime)) {
            sql += " and loginTime >=to_date(?,'yyyy-mm-dd')";//oracle的to_date方法
            paramList.add(startTime);
        }
        if (StringUtils.isNotBlank(endTime)) {
            sql += "  and loginTime <=to_date(?,'yyyy-mm-dd')";
            paramList.add(endTime);
        }
        sql += " order by loginTime desc";
        return (pagination) ? getJdbcTemplateWithPagination().queryForListWithPagination(sql, paramList.toArray()) :
                getJdbcTemplate().queryForList(sql, paramList.toArray());
    }


你可能感兴趣的:(多个约束条件的查询)