MyBatis 注解

注解:为了简化配置文件.Mybatis 的注解简化 mapper.xml 文件.

如果涉及动态 SQL 依然使用 mapper.xml

mapper.xml 和注解可以共存.

使用注解时 mybatis.xml 中<-mappers>使用<-package/>或者<-mapper class=””/>

实现查询

实现新增

实现修改

实现删除

使用注解通过AutoMapping结合别名实现多表查询

  • 使用注解实现<-resultMap>功能(不推荐使用)
    • 以 N+1 举例
    • 在 StudentMapper 接口添加查询
    • 在 TeacherMapper 接口添加
      • @Results() 相当于<-resultMap>
      • @Result() 相当于<-id/>或<-result/>
      • @Result(id=true) 相当与<-id/>
      • @Many() 相当于<-collection/>
      • @One() 相当于<-association/>