最近在写ssm+shiro的教务管理系统学习过程中,查询某个学生的选课信息,在mapper中同时传入了两个形参:
List<SelectCourse > selectCourseByStudentId(PagingVO pagingVO,SelectCourse selectCourse);
mapper对应的xml为:
<!--分页查询已选课表-->
<select id="selectCourseByStudentId" resultMap="SelectCourse">
select * from select_course
where student_id = #{studentId} and mark is NULL
limit #{toPageNo},#{pageSize}
</select>
结果在运行的时候出现错误:
Parameter 'studentId' not found. Available parameters are [0, 1, param1, param2]
经过一番排查和百度经验,发现如果mapper中同时传入了两个形参的时候,可以通过@param注解来解决这个问题:
/**
*分页查询已选课程
*/
List<SelectCourse > selectCourseByStudentId(@Param("pagingVO")PagingVO pagingVO, @Param("selectCourse")SelectCourse selectCourse);
对应的.xml为:
<!--分页查询已选课表-->
<select id="selectCourseByStudentId" resultMap="SelectCourse">
select * from select_course
where student_id = #{selectCourse.studentId} and mark is NULL
limit #{pagingVO.toPageNo},#{pagingVO.pageSize}
</select>
问题得到解决!
另外,要注意resultMap和resultType的使用:当查询结果是一个参数时用resultType,当查询结果为多个参数组成的列表时用resultMap。
2018.8.10 教务管理系统遇到问题!
不忘初心,在实践中学习,在学习中成长!