初接触到MyBatis的级联,建立一个studentBean和studentCardBean,在查询student的信息的同时能够获取studentCard信息,因此需要在studentBean中建立一个studentCardBean类型的变量。
这时我们在studentCardMapper中已经有了依据学生ID对学生卡信息进行查询的功能,那么当我们查询学生时使用association进行级联查询即可同时获取两种信息。
其中,association的属性当中,property是studentBean中的属性名称,而需要注意的是,column是指在studentMapper的select语句中选择数据库的ID列的名称,而不是studentBean中的属性名称。这样就可以在studentBean中通过级联获取一个studentC ardBean对象属性啦。
以上代码地址:https://gitee.com/ArainChen/MyTestProject1