【问题标题】:myBatis select to existing objectmyBatis 选择现有对象
【发布时间】:2016-06-07 14:28:59
【问题描述】:

是否可以运行一个选择查询来使用 myBatis 更新现有的 java 对象。

例如给定这个现有的 java 对象:

Customer{
    int id;
    String firstName;
    String lastName;
}

假设我已经有一个 ID 为 1 的客户实例 C。

如何运行 myBatis 选择查询来更新该实例而不是创建一个新实例。

【问题讨论】:

  • 没有任何 myBatis 教程解释如何做到这一点吗?

标签: mybatis


【解决方案1】:

如果您需要更新内存中的对象,则必须使用查询结果设置内存中对象的每个属性。

Customer customer = new Customer(1,"C",null);//Object in memory
Customer customerQuery = selectQueryMyBatis(); //Query object

customer.setFirstName(customerQuery.getFirstName());
customer.setLastName(customerQuery.getLastName());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 2017-06-19
    相关资源
    最近更新 更多