1) web阶段学的东西多而杂,要学会分类,思路清晰了是第一步,用的时候再去查相应的文档.2) 需要细心,有很多用的到字符串拼接的地方,一不小心就会拼错,到时候会报sql语法错误如下代码:
[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());
}
|