日期:2014-05-20 浏览次数:20620 次
public List<Map<String, Object>> findMovieByType(String type,String spinnerRegion,String spinnerActor,String spinnerYear,String television,int pageNum,int numSize){ Cursor cursor = db.rawQuery("select * from Online_All where type=? and region=? and actor=? and year=? and television=? limit ?,?", new String[]{String.valueOf(type),String.valueOf(spinnerRegion),String.valueOf(spinnerActor), String.valueOf(spinnerYear),String.valueOf(television),String.valueOf(m),String.valueOf(numSize)}); }
if(type==null){ Cursor cursor = db.rawQuery("查询语句里面 不写 type=? "); } if(spinnerRegion==null){ Cursor cursor = db.rawQuery("查询语句里面 不写 region=?"); } 。。。。等等 这样写的话 就不用说了 太不实际了。。。
StringBuilder sql = StringBuilder("select * from Online_All where 1=1"); if (type!=null && !type.isEmpty()) sql.append(" and type = '").append(type).append("'"); if (spinnerRegion!=null && !spinnerRegion.isEmpty()) sql.append(" and region = ").append(spinnerRegion).append("'"); ... //so on Cursor cursor = db.rawQuery(sql.toString());
------解决方案--------------------