public List<WfConfigMVO> queryList(WfConfigMVO wfConfig) throws SysException {
StringBuffer sql = new StringBuffer();
sql.append("select WF_CONFIG_ID,WF_TEMPL_KEY,TIME_LIMIT,WF_NAME ");
sql.append("from wf_config ");
sql.append("where 1=1");
List<WfConfigMVO> resultList = null;
List<Object> params = new ArrayList<Object>();
try {
if (wfConfig != null) {
if (isNotBlank(wfConfig.getWfConfigId())) {
sql.append(" and WF_CONFIG_ID=?");
params.add(wfConfig.getWfConfigId());
}
if (isNotBlank(wfConfig.getWfTemplKey())) {
sql.append(" and WF_TEMPL_KEY=?");
params.add(wfConfig.getWfTemplKey());
}
if (isNotBlank(wfConfig.getTimeLimit())) {
sql.append(" and TIME_LIMIT=?");
params.add(wfConfig.getTimeLimit());
}
if (isNotBlank(wfConfig.getWfName())) {
//开始我使用了下面的这种方法
// sql.append(" and WF_NAME like '%?%'");
// params.add(wfConfig.getWfName()); 这样做就会报SqlException
//sql.append(" and WF_NAME like %?%");这里不要单引号也是会报异常的
//正确的方法如下
sql.append(" and WF_NAME=?");
params.add("%"+wfConfig.getWfName()+"%");//把‘%’放进参数中传递进去OK
}
}
resultList = jdbcTemplate.query(sql.toString(),
params.toArray(),
new BeanPropertyRowMapper<WfConfigMVO>(WfConfigMVO.class));
} catch (DataAccessException e) {
e.printStackTrace();
logger.error("查询WfConfig错误:{}", e.getMessage());
throw new SysException("10000", "查询WfConfig错误", e);
}
return resultList;
}