查询对象,
Student student = return jdbcTemplate.queryForObject("select * from student_id = ?", new Object[] { studentId }, studentRowMapper);
如有疑问,
List<Student> students = return jdbcTemplate.query("select * from class_room_id = ?", new Object[] { classRoomId }, studentRowMapper);
jdbcTemplate.queryForObject
和jdbcTemplate.query
在上述Spring Boot 2.4.X中已弃用
正如该类的 javadoc 以及 升级/迁移指南中所解释的,它解释了您应该使用 varargs 方法。
jdbcTemplate.queryForObject("select * from student_id = ?", studentRowMapper, studentId);
和
List<Student> students = return jdbcTemplate.query("select * from class_room_id = ?", studentRowMapper, classRoomId);
您应该更改输入变量和映射器的顺序。您还应该使用 varargs 而不是 Object[ ]。所以你的代码是:
Student student = return jdbcTemplate.queryForObject("select * from student_id = ?",
studentRowMapper, studentId );
和
List<Student> students = return jdbcTemplate.query("select * from class_room_id = ?",
studentRowMapper, new Object[] { classRoomId });