CODING COMING.
// 组合模糊查询 根据年龄 和 姓名 模糊查询 学生。public List<Student> findTwo(int age, String name) {List<Student> list = new ArrayList<Student>();StringBuffer sql = new StringBuffer("select * from student where 1 = 1");// 动态设置值 使用的。List<Object> paramList = new ArrayList<Object>();if (age >= 0) {sql.append(" and age = ?");paramList.add(age);}if (name != null && !name.trim().equals("")) {sql.append(" and name like ?");paramList.add("%" + name + "%");}// like concat('%', ?, '%') 也可Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;try {conn = BaseDao.getConn();// sql语句在前... 无效的列索引.ps = conn.prepareStatement(sql.toString());for (int i = 0; i < paramList.size(); i++) {ps.setObject(i + 1, paramList.get(i));}rs = ps.executeQuery();while (rs.next()) {Student stu = new Student();stu.setId(rs.getInt("id"));stu.setName(rs.getString("name"));stu.setBirth(rs.getString("birth"));stu.setAge(rs.getInt("age"));list.add(stu);}} catch (SQLException e) {e.printStackTrace();} finally {BaseDao.release(conn, ps, rs);}return list;}
还有一篇文章是.net 里面的 多条件组合查询。
😁😁
.net树控件,多条件组合查询