初接触到MyBatis的级联,建立一个studentBean和studentCardBean,在查询student的信息的同时能够获取studentCard信息,因此需要在studentBean中建立一个studentCardBean类型的变量。

MyBatis级联(一对一级联association)studentC ardBean
MyBatis级联(一对一级联association)studentBean

​这时我们在studentCardMapper中已经有了依据学生ID对学生卡信息进行查询的功能,那么当我们查询学生时使用association进行级联查询即可同时获取两种信息。

MyBatis级联(一对一级联association)studentC ardMapper
MyBatis级联(一对一级联association)studentMapper

​其中,association的属性当中,property是studentBean中的属性名称,而需要注意的是,column是指在studentMapper的select语句中选择数据库的ID列的名称,而不是studentBean中的属性名称。这样就可以在studentBean中通过级联获取一个studentC ardBean对象属性啦。


以上代码地址:https://gitee.com/ArainChen/MyTestProject1

相关文章:

  • 2021-08-23
  • 2022-12-23
  • 2021-11-15
  • 2021-05-05
  • 2021-08-15
  • 2021-12-31
  • 2022-12-23
猜你喜欢
  • 2022-02-17
  • 2022-02-07
  • 2021-04-29
  • 2021-10-13
  • 2022-01-08
相关资源
相似解决方案