zoukankan      html  css  js  c++  java
  • 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());
            }
        }
  • 相关阅读:
    类的静态成员
    ActionController::InvalidAuthenticityToken 解决办法
    Ruby的动态特性
    (转)右下角弹出消息框
    使用 Visual C++ 2008 功能包加强 Windows 应用程序
    Ajax以responseXML返回,客户端(IE)不能分析xml问题
    css的精髓是布局,而不是样式——之二
    字符编码的一些内容
    2009年好运!牛年要牛起来
    OpenLayers介绍
  • 原文地址:https://www.cnblogs.com/flypig666/p/11506487.html
Copyright © 2011-2022 走看看