海螺里的风

spring JdbcTemplate多个占位符参数传递




留着备用,JdbcTemplate多个占位符参数传递

	public List<Map<String, Object>> getList(Map<String, Object> param,int start, int number) {
		List <Object> queryList=new  ArrayList<Object>();
		String sql="SELECT * from users t where 1=1 ";
			if(param.get("username")!=null&&(!"".equals(param.get("username")))){
				sql+= " and t.username LIKE ? ";
				queryList.add("%"+param.get("username")+"%");
			}
			if(param.get("startdate")!=null&&(!"".equals(param.get("startdate")))){
				sql+= " and t.registertime>STR_TO_DATE(?,'%Y-%m-%d')";
				queryList.add(param.get("startdate"));
			}
			if(param.get("enddate")!=null&&(!"".equals(param.get("enddate")))){
				sql+= " and t.registertime<=STR_TO_DATE(?,'%Y-%m-%d 23:59:59')";
				queryList.add(param.get("enddate"));
			}
				sql+= " LIMIT ?,?";
				queryList.add(start);
				queryList.add(number);
		return this.jdbcTemplate.queryForList(sql,queryList.toArray());
	}

 

打赏
码字很辛苦,转载请注明来自海螺里的风《spring JdbcTemplate多个占位符参数传递》

评论