欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

mybatis 返回列表类型的数据

最编程 2024-06-29 11:11:37
...

studends表里一条teacher_id 数据对应多条 student_id数据,所以通过teacher_id 查询出来的student_id 是一个List。

mybatis代码如下:

//返回类型是String类型的student_id
<resultMap id="studentIdResult" type="java.lang.String" >
    <result column="student_id" property="studentId" jdbcType="VARCHAR" />
</resultMap>
//入参类型(parameterType)是String类型 teacherId
<select id="getStudentsByTeacherId" resultMap="studentIdResult" parameterType="java.lang.String" >
    select student_id
    from student
    where teacher_id = #{id,jdbcType=VARCHAR}
</select>