今天要大家整理的内容是:
1.延迟加载和立即加载的概念
延迟加载:就是在需要用到数据时才进行加载,不需要用到数据时就不加载数据
立即加载:加载一个实体 时,会立即从数据库中查询,与其关联的类也会被同时查询
2.什么是mybatis的一级缓存和二级缓存
一级缓存:SqlSession 级别的缓存,只要 SqlSession 没有 flush 或 close,它就存在
二级缓存:mapper 映射级别的缓存,多个 SqlSession 去操作同一个 Mapper 映射的 sql 语句,多个SqlSession 可以共用二级缓存,二级缓存是跨 SqlSession 的
3.Mybatis如何使用注解开发的(如何配置)
在mapper接口中的方法上配置,比如
一对一:
@Select("select * from account")
@Results(id="accountMap",value = {
@Result(id=true,column = "id",property = "id"),
@Result(column = "uid",property = "uid"),
@Result(column = "money",property = "money"),
@Result(property = "user",column = "uid",one=@One(select="com.itheima.dao.IUserDao.findById",fetchType= FetchType.EAGER))
})
List<Account> findAll();
一对多:
@Select("select * from user")
@Results(id="userMap",value={
@Result(id=true,column = "id",property = "userId"),
@Result(column = "username",property = "userName"),
@Result(column = "address",property = "userAddress"),
@Result(column = "sex",property = "userSex"),
@Result(column = "birthday",property = "userBirthday"),
@Result(property = "accounts",column = "id",
many = @Many(select = "com.itheima.dao.IAccountDao.findAccountByUid",
fetchType = FetchType.LAZY))
})
List<User> findAll(); |