[Java] 纯文本查看 复制代码
@Override
public List<Route> findByPage(int cid, int start, int pageSize,String rname) {
//
// String sql = "select * from tab_route where cid = ? limit ? , ?";
//
// return jtl.query(sql,new BeanPropertyRowMapper<Route>(Route.class),cid,start,pageSize);
String sql = "select * from tab_route where 1=1";
StringBuilder sb = new StringBuilder(sql);
ArrayList arr = new ArrayList<>();
if (cid != 0) {
sb.append(" and cid = ? ");
arr.add(cid);//添加?对应的值
}
if (rname != null && rname.length() > 0&& !"null".equals(rname)) {
sb.append(" and rname like ?");
arr.add("%" + rname + "%");
}
arr.add(start);
arr.add(pageSize);
sb.append(" limit ? , ? ");
sql = sb.toString();
return jtl.query(sql, new BeanPropertyRowMapper<Route>(Route.class), arr.toArray());
}