• mybatis学习:mybatis注解开发一对一的查询配置


    实体类:

     1 public class Account {
     2 
     3     private Integer id;
     4     private Integer uid;
     5     private Double money;
     6 
     7     private User user;
     8 
     9     public User getUser() {
    10         return user;
    11     }
    12 
    13     public void setUser(User user) {
    14         this.user = user;
    15     }
    16     public Integer getId() {
    17         return id;
    18     }
    19 
    20     public void setId(Integer id) {
    21         this.id = id;
    22     }
    23 
    24     public Integer getUid() {
    25         return uid;
    26     }
    27 
    28     public void setUid(Integer uid) {
    29         this.uid = uid;
    30     }
    31 
    32     public Double getMoney() {
    33         return money;
    34     }
    35 
    36     public void setMoney(Double money) {
    37         this.money = money;
    38     }
    39 
    40     @Override
    41     public String toString() {
    42         return "Account{" +
    43                 "id=" + id +
    44                 ", uid=" + uid +
    45                 ", money=" + money +
    46                 '}';
    47     }
    48 }

    dao层:

     1 public interface IAccountDao {
     2 
     3     /**
     4      * 查询所有账户,并且获取每个账户所属的用户信息
     5      * @return
     6      */
     7     @Select("select * from account")
     8     @Results(id = "accountMap",value = {
     9             @Result(id = true,column = "id",property = "id"),
    10             @Result(column = "uid",property = "uid"),
    11             @Result(column = "money",property = "money"),
    12             @Result(property = "user",column = "uid",one = @One(select = "cn.flypig666.dao.IUserDao.findById",fetchType = FetchType.EAGER))
    13     })
    14     List<Account> findAll();
    15 }

    test:

    @Test
        public void testFindAll(){
            List<Account> accounts = accountDao.findAll();
            for (Account account : accounts) {
                System.out.println("账户信息:");
                System.out.println(account);
                System.out.println(account.getUser());
            }
        }
  • 相关阅读:
    随机-byte编码
    dataframe骚操作,待续
    oracle中的rowid
    java提高篇-----理解java的三大特性之继承
    staruml使用教程
    黑马程序员:HTML习题1
    Cocos2d-x-->CCSprite 动画
    地址栏传参中文乱码详解
    Qt学习第二天
    Lync 2010 升级到2013 之部署2013前端服务器!
  • 原文地址:https://www.cnblogs.com/flypig666/p/11506487.html
Copyright © 2020-2023  润新知