Home > Back-end >  Spring Mvc controller receives the object always null
Spring Mvc controller receives the object always null

Time:09-25

Soon I small white, just contact with SSM framework, the following problems

Regardless of the database has the data page always jump out "the user does not exist", namely the controller corresponding to the teacher in==null

@ Controller
@ RequestMapping ("/the teacher ")
Public class ReUserInfoController {
The @autowired
Private ReUserInfoService ReUserInfoService;

/* *
* teacher login
* @ param copyUserInfo
* @ return
*/
//scanning is the action of the JSP page parameters above
@ RequestMapping ("/teacher_login ")
Public String teacher_login (CopyUserInfo CopyUserInfo, it request, Model Model) {
String MSG="";
//according to login account to judge whether the user is
CopyUserInfo. The teacher=reUserInfoService selectTeacherByRID (CopyUserInfo getTeacher_RID ());
If the teacher (==null) {
MSG="the user does not exist!" ;
} else {
If (the teacher getTeacher_Pass (.) the equals (copyUserInfo. GetTeacher_Pass ())) {
/* the user information into the session */
Request. GetSession (). The setAttribute (" the userInfo ", the teacher);
//get sessionid
String sessionId=request. GetSession (). The getId ();
Model. The addAttribute (" sessionId "sessionId);
//into the main interface
Return "/teacher_main";
} else {
MSG="password error!" ;
}
}
Model. The addAttribute (" MSG ", MSG);
//returns the page, login is address
Return "/login";
}
}

Idea below seems to be able to successfully find the data

CodePudding user response:

Action if no write wrong, in the name of the form controls and entity class attribute name if is consistent, meng, don't know what wrong
Attached to the JSP interface

CodePudding user response:

On your teacher_ID code is equal to null, you can test the id look output, suggest the parameters of the receiving written as an Integer id that receive the front desk to get the id of the value directly

CodePudding user response:

You this IDEA console log shows you teacher_RID is 10000 and can check the data, but if (the teacher==null) is true, that the problem is the query results are not mapped back to the controller layer CopyUserInfo, problems should be out in your persistence layer, the mapping problem, you should debug is that part of the code

CodePudding user response:

First of all, print you receive teacher_RID, have a look at whether or not received, if it is null, you can use the request. GetParamter (); Available, but can be by annotation @ RequestParam (" ") annotation,
If the received there is value in teacher_RID, and found out the data, but judgment is null, then take a look at your mapper file the return type of statement, whether CopyUserInfo, verify the return type of his statement is correct one or two also said not clearly, because I don't know whether you are using annotations or XML file, if it is the return type of the XML file you is to configure an alias or resultmap, or is the package path, as long as you can find out data, receives the value, it must be your mapper file statement the return type of problem

CodePudding user response:

always coke reference 3 floor response:
you this IDEA console log shows you teacher_RID is 10000 and can check the data, but if the teacher (==null) is true, that the problem is the query results are not mapped back to the controller layer CopyUserInfo, problems should be out in your persistence layer, the mapping problem, you should debug is that part of the code


I saw, in the breakpoint way what is found at the front desk and in parameter, what has been the parameters, as if it hasn't been changed, in addition to the rest of the teacher_RID and teacher_Pass, has always been a null

CodePudding user response:

Said 3 floor to check the entity class and mapping database field corresponding to the field name field names if no problem, take a look at whether there is int field corresponding data is null int field to try an initial value

CodePudding user response:

Thank you, problem solving, didn't add resultmapper mapper, make up the solved and attributes, before being misled

CodePudding user response:

reference 6 floor coding to reply:
said 3 floor to check the entity class and mapping database field corresponding to the field name field names if no problem, take a look at whether there is int field corresponding data to an initial value is null int field try

Excuse me, mapper, resultmapper are a must, because I changed my previous model can also be run without this

CodePudding user response:

refer to the eighth floor Altoriadd response:
Quote: reference 6 floor coding to reply:
said 3 floor to check the entity class and mapping database field corresponding to the field name field names if no problem, take a look at whether there is int field corresponding data to an initial value is null int field try

Excuse me, mapper, resultmapper are a must, because I changed my previous model can also be run without this

Should be the default mapping, resultmapper is not necessary

CodePudding user response:

refer to the eighth floor Altoriadd response:
Quote: reference 6 floor coding to reply:
said 3 floor to check the entity class and mapping database field corresponding to the field name field names if no problem, take a look at whether there is int field corresponding data to an initial value is null int field try

Excuse me, mapper, resultmapper are a must, because I changed my previous model can also be run without this


Mybatis default map, but you must be the name of the table fields of entity class and attribute names the same. If you don't like resultMap them is required
  • Related