视频上没说查询学生,我就自己写了下,但是输出不出来呢 求解答
在Main类中:
else if("c".equals(type))
{
System.out.print("请输入要查询的学生准考证号:");
String examid=br.readLine();
Studentdao dao=new Studentdao();
dao.find(examid);
}
在Studentdao类中
public Student find(String examid)
{
try {
Document document=XmlUtils.getDocument();
NodeList list=document.getElementsByTagName("student");
for(int i=0;i<list.getLength();i++)
{
Element student_tag=(Element) list.item(i);
if(student_tag.getAttribute("examid").equals(examid))
{
Student s=new Student();
s.setExamid(examid);
s.setIdcard(student_tag.getAttribute("idcard"));
s.setName(student_tag.getElementsByTagName("name").item(0).getTextContent());
s.setLocation(student_tag.getElementsByTagName("location").item(0).getTextContent());
s.setGrade(Double.parseDouble(student_tag.getElementsByTagName("grade").item(0).getTextContent()));
return s;
}
}
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
为什么不能输出要查找的学生信息啊? |