实体类
//多对一(mybatis中称之为一对一)的映射:一个账户只能属于一个用户 private User user; public User getUser() { return user; } public void setUser(User user) { this.user = user; }
接口
/** * 查询所有账户,并且获取每个账户所属的用户信息 * @return */ @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)) })