Student [FlowID=0, Type=0, IDCard=22222222222222, ExamCard=null, StudentName=null, Location=null, Grade=0] strangely only IDCard assigned values, Student class is also very normal, no error, want to broken head liquid don't understand, please help, below is the code,
//test
@ Test
Public void testGet () {
String SQL="select Flow_ID as FlowID, Type, ID_Card IDCard,"
+ "Exam_Card ExamCard, Student_Name StudentName, Location,"
+ "Grade from stud_infor Where Grade=? ";
Student Student=dao. Get (Student class, SQL, 60).
System. The out. Println (student);
}
//query methods
The public & lt; T> T get (Class
T the entity=null;
The Connection Connection=null;
PreparedStatement ps=null;
The ResultSet rs=null;
Try {
//
The connection=JDBCTools. GetConnection ();
Ps=connection. PrepareStatement (SQL);
for (int i=0; i
}
Rs=ps. ExecuteQuery ();
//
The ResultSetMetaData RSMD=rs. For getMetaData ();
//
Map
{if (rs. Next ())
for (int i=0; i
The Object columnValue=https://bbs.csdn.net/topics/rs.getObject (columnLable);
The map. The put (columnLable, columnValue);
}
}
//
If (map. The size () & gt; 0 {
The entity=clazz. NewInstance ();
For (Map. Entry
String fieldName=entry. GetKey ();
The Object fieldValue=https://bbs.csdn.net/topics/entry.getValue ();
//ReflectionUtils. SetFieldValue (entity, fieldName, fieldValue);
BeanUtils. SetProperty (entity, fieldName, fieldValue);
}
}
} the catch (Exception e) {
e.printStackTrace();
} the finally {
JDBCTools. Release (rs, ps, connection).//close resources
}
Return the entity;
}
//Student class
Public class Student {
Private int FlowID;//serial number
Private int Type.//cet
Private String IDCard; Id//
Private String ExamCard; No.//admission ticket
Private String StudentName;//the student's name
Private String Location;//area
Private int Grade;//student achievement
Public String getLocation () {
Return the Location;
}
Public void setLocation (String location) {
Location=Location;
}
Public int getFlowID () {
Return FlowID;
}
Public void setFlowID (int flowID) {
FlowID=FlowID;
}
Public int getType () {
The return Type.
}
Public void setType (int type) {
Type=Type;
}
Public String getIDCard1 () {
Return IDCard;
}
Public void setIDCard (String iDCard) {
IDCard=IDCard;
}
Public String getExamCard () {
Return ExamCard;
}
Public void setExamCard (String examCard) {
ExamCard=ExamCard;
}
Public String getStudentName () {
Return StudentName;
}
Public void setStudentName (String studentName) {
StudentName=StudentName;
}
Public int getGrade () {
Return Grade;
}
Public void setGrade (int grade) {
Grade=Grade;
}
Public Student () {
super();
}
Public Student (int flowID, int type, String iDCard, String examCard, String studentName, String location,
{int grade)
super();
FlowID=FlowID;
Type=Type;
IDCard=IDCard;
ExamCard=ExamCard;
StudentName=StudentName;
Location=Location;
Grade=Grade;
}
@ Override
Public String toString () {
Return "Student [FlowID=" + + "FlowID, Type=" + + "Type, IDCard=" + IDCard + ", ExamCard="+ ExamCard
+ ", StudentName="+ StudentName +", the Location="+ Location +" Grade="+ +"] "Grade;
}
}
CodePudding user response:
You of the attribute name to lowercase letter, BeanUtils is determined based on the setter attribute nameCodePudding user response:
It is these small problems usually do not pay attention to can let a person crazyPublic class Student {
Private int flowID;//serial number
private int type;//cet
Private String iDCard; Id//
Private String examCard; No.//admission ticket
Private String studentName;//the student's name
Private String location;//area
Public int getFlowID () {
Return flowID;
}
String SQL="select Flow_ID as flowID, type, ID_Card iDCard,"
+ "Exam_Card examCard, Student_Name studentName, location,"
+ "Grade from stud_infor Where Flow_ID=?" ;
Results returned Student [flowID=1, type=4, iDCard=412824195263214584, examCard=200523164754000, studentName=Zhang Feng, zhengzhou location=]
CodePudding user response:
Thank you upstairs!!!!!!!!!!!!!!CodePudding user response:
Entity class bean should have corresponding values the get () and set () method to the assignment