欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

多条件查询

程序员文章站 2024-03-03 16:23:28
...

public List<Student> selall(Student student) {
List<Student> li;
String sql="select * from stu_table where 1=1 ";
if(student.getStuID()!=0){
sql+=" and stuID like '%"+student.getStuID()+"'";
}
if(student.getStuSN()!=null && !(student.getStuSN().equals(""))){
sql+=" and stuSN like '%"+student.getStuSN()+"'";
}
if(student.getStuName()!=null&& !(student.getStuName().equals(""))){
sql+=" and stuName like '%"+student.getStuName()+"'";
}
if(student.getStuSex()!=null && !(student.getStuSex().equals(""))){
sql+=" and stuSex like '%"+student.getStuSex()+"'";
}
System.out.println(sql);


li=this.getJdbcTemplate().query(sql, new RowMapper(){


public Object mapRow(ResultSet res, int arg1) throws SQLException {
Student student=new Student();
student.setParentid(res.getInt("parentid"));
student.setPersonID(res.getString("personID"));
student.setStrongSuit(res.getString("strongSuit"));
student.setStuAge(res.getInt("stuAge"));
student.setStuBirthDate(res.getDate("stuBirthDate"));
student.setStuBirthPlace(res.getString("stuBirthPlace"));
student.setStuBlood(res.getString("stuBlood"));
student.setStuID(res.getInt("stuID"));
student.setStuName(res.getString("stuName"));
student.setStuNum(res.getString("stuNum"));
student.setStuSex(res.getString("stuSex"));
student.setStuSN(res.getString("stuSN"));
return student;
}



});
return li;
}
相关标签: SQL