myBatis select 到现有对象
myBatis select to existing object
是否有可能 运行 一个 select 查询用 myBatis 更新现有的 java 对象。
例如给定这个现有的 java 对象:
Customer{
int id;
String firstName;
String lastName;
}
假设我已经有一个 ID 为 1 的客户实例 C。
我如何 运行 myBatis select 查询来更新该实例而不是创建新实例。
如果需要更新内存中的对象,则必须setter内存中对象的每个属性都包含查询结果。
Customer customer = new Customer(1,"C",null);//Object in memory
Customer customerQuery = selectQueryMyBatis(); //Query object
customer.setFirstName(customerQuery.getFirstName());
customer.setLastName(customerQuery.getLastName());
是否有可能 运行 一个 select 查询用 myBatis 更新现有的 java 对象。
例如给定这个现有的 java 对象:
Customer{
int id;
String firstName;
String lastName;
}
假设我已经有一个 ID 为 1 的客户实例 C。
我如何 运行 myBatis select 查询来更新该实例而不是创建新实例。
如果需要更新内存中的对象,则必须setter内存中对象的每个属性都包含查询结果。
Customer customer = new Customer(1,"C",null);//Object in memory
Customer customerQuery = selectQueryMyBatis(); //Query object
customer.setFirstName(customerQuery.getFirstName());
customer.setLastName(customerQuery.getLastName());