映射文件------------------------
<mapper namespace="com.glut.mapper.StudentMapper">
<resultMap id="baseResult" type="com.glut.model.Students">
<!-- 将数据库的列映射或者说重命名,需要映射每个字段 -->
<id property="stuId" column="STU_ID"/>
<result property="colname" column="COL_NAME"/>
<result property="pname" column="P_NAME"/>
<result property="stuname" column="STU_NAME"/>
<result property="stupassword" column="STU_PASSWORD"/>
<result property="stuclass" column="STU_CLASS"/>
<result property="stuphone" column="STU_PHONE"/>
<result property="stuaddress" column="STU_ADDRESS"/>
<result property="stucard" column="STU_CARD"/>
<result property="stuqq" column="STU_QQ"/>
<result property="stuparphone" column="STU_PAR_PHONE"/>
<result property="stusex" column="STU_SEX"/>
</resultMap>
<!-- 语句ID: selectForLogin 对应UserMapper里的方法名 -->
<select id="StuDoLogin" parameterType="com.glut.model.Students" resultMap="baseResult">
<!-- select * from 数据库表 where 数据库字段 = model中的类字段…… ;#{}是mybatis中的占位符语法-->
select * from STUDENTS where stu_Id=#{stuId} and stu_password=#{stupassword}
</select>
</mapper>
---------------------------------------------
这是控制器的代码
@Controller
//RequestMapping标注在类前面
@RequestMapping("/student")
public class StuController {
@Autowired
IStudentService studentService;
@RequestMapping("/studentLogin")
public String studentLogin(Students student,ModelMap modelMap){ // 通过java反射将提交的请求参数值封装到Students对应的属性上
System.out.println(student);//该student是从表单获取的
Students stu = this.studentService.StuDoLogin(student);
System.out.println(stu);
if (stu!=null){
modelMap.addAttribute("stu",stu);
}else{
System.out.println("登录失败");
return "student";
}
return "studentSys";
}
}
-------------------------------
接口
public interface IStudentService{
public Students StuDoLogin(Students student);
}
------------------------------
接口实现类
@Service("studentService")//bean的id=studentService
public class StudentServiceimpl implements IStudentService {
//自动从spring容器中查找叫studentMapper的bean并注入
@Autowired
StudentMapper studentMapper;
@Override
public Students StuDoLogin(Students student) {
return studentMapper.StuDoLogin(student);
}
}
-------------------------------------------------
控制台输出语句:
Students{stuId='3172082081101', colname='null', pname='null', stuname='null', stupassword='123456', stuclass='null', stuphone='null', stuaddress='null', stucard='null', stuqq='null', stuparphone='null', stusex='null'}
2021-04-29 12:57:15,172 [http-nio-8080-exec-4] DEBUG [com.glut.mapper.StudentMapper.StuDoLogin] - ==> Preparing: select * from STUDENTS where stu_Id=? and stu_password=?
2021-04-29 12:57:15,172 [http-nio-8080-exec-4] DEBUG [com.glut.mapper.StudentMapper.StuDoLogin] - ==> Parameters: 3172082081101(String), 123456(String)
2021-04-29 12:57:15,198 [http-nio-8080-exec-4] DEBUG [com.glut.mapper.StudentMapper.StuDoLogin] - <== Total: 0
null
登录失败
描述的不够清楚, 你是想说 他本来应该出现数据 然后没有出现数据的意思么?
你数据库本身就没有这条数据啊,属于正常的呀。