遇到一个很奇怪的问题,MyBatis使用对象传参,感觉写的没问题,但是运行后,MyBatis就会卡住不动
servlet层
if("selectByNameByEmailByAge".equals(re)){
Student stu = new StudentServiceImpl().selectByNameByEmailByAge(new Student(request.getParameter("name"),request.getParameter("email"),Integer.parseInt(request.getParameter("age"))));
text = stu != null ? stu.toString() : "没有查询到哦!";
System.out.println(text);
}
dao层
Student selectByNameByEmailByAge(Student stu);
Mapper文件
<select id="selectByNameByEmailByAge" resultType="Student">
select *
from student
where name = #{name} and email = #{email} and age = #{age}
</select>
实体类
public class Student {
private int id;
private String name;
private String email;
private int age;
public Student(int id, String name, String email, int age) {
this.id = id;
this.name = name;
this.email = email;
this.age = age;
}
public Student(String name, String email, int age) {
this.id = id;
this.name = name;
this.email = email;
this.age = age;
}
实体类中省略getset方法
我反复阅读都没问题,但是就是会卡住,我也尝试过在Mapper写其他的,比如加上参数类型什么的,但是都没用,直到我又删了重新写了一遍,居然就好了!很奇怪!