注解 作用
@Insert 实现新增
@Update 实现更新
@Delete 实现删除
@Select 实现查询
@Result 实现结果集封装
@Results 可以与@Result 一起使用,封装多个结果集
@ResultMap 实现引用@Results 定义的封装
@One 实现一对一结果集封装
@Many 实现一对多结果集封装
@SelectProvider 实现动态 SQL 映射
@CacheNamespace 实现注解二级缓存的使用

Result注解使用

    @Select("SELECT * FROM user")
    @Results({
            @Result(id=true,column = "id",property ="id"),
            @Result(column = "username",property ="username"),
            @Result(column = "sex",property ="sex"),
            @Result(column = "address",property ="address"),
            @Result(column = "birthday",property ="birthday")
    })
    List<User> find();

一对一查询

    @Select("SELECT * FROM account")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "uid",property = "uid"),
            @Result(column = "money",property = "money"),
            @Result(column = "uid",property = "user",one = @One(select = "wang.ismy.mybatis.dao.UserDao.findById",fetchType = FetchType.LAZY))
    })
    List<Account> findAll();

一对多查询

    @Select("SELECT * FROM user")
    @Results({
            @Result(id=true,column = "id",property ="id"),
            @Result(column = "username",property ="username"),
            @Result(column = "sex",property ="sex"),
            @Result(column = "address",property ="address"),
            @Result(column = "birthday",property ="birthday"),
            @Result(column = "id",property = "account",
                    many = @Many(select = "wang.ismy.mybatis.dao.AccountDao.findById",fetchType = FetchType.LAZY))
    })
    List<User> find();

开启二级缓存

@CacheNamespace
public interface UserDao {}

results matching " "

No results matching " "

results matching " "

No results matching " "