gpt4 book ai didi

java - MyBatis select by id 总是返回零

转载 作者:行者123 更新时间:2023-11-29 05:58:49 33 4
gpt4 key购买 nike

具有以下配置:

POJO:

public class Student {
private int studentId;
private String name;
private String email;
// getters and setters
}

StudentMapper.xml

...
<select id="findStudentById" parameterType="int" resultType="Student">
SELECT student_id, name, email FROM Student WHERE studentId = #{studentId}
</select>
...

StudentMapper 界面

public interface StudentMapper {
...
Student findStudentById(int studentId);
...
}

问题是每当我运行 StudentService.findStudentById(studentId)(我没有把它放在这里)我得到的是相同的数字(零) 每次(我表中的 student_id 是 auto_generated 并且从 1 而不是 0 开始)

编辑:但其他参数(姓名和电子邮件)已正确返回

最佳答案

您没有向我们展示在数据库中插入数据的代码,所以我猜测您可能做错了什么。尽管您在表中使用了 auto_generated 列,但在插入 Student 数据时,您会向其发送 int studentId。我还假设您没有为它定义任何值,因为您希望它是自动生成的,所以 MyBatis 会将 int 的默认值添加到 student_id,即 0。

关于java - MyBatis select by id 总是返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46844579/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com