如何将类的预定义映射器类实现到另一个具有第一类作为对象的类的新映射器类中
public class Class2Mapper implements ResultSetMapper<Class2>
{
public Class2 map(int index, ResultSet rs, StatementContext ctx)
{
Class2 myC2 = new Class2();
//Do something to Map myC2.class1Object with rs
//Do some mapping with other variables of myC2
return myC2;
}
}
假设Class1Mapper
已经定义。
答案 0 :(得分:0)
你也可以在另一个映射器中使用映射器。
public class Class2Mapper implements ResultSetMapper<Class2> {
private Class1Mapper class1Mapper;
public Class2Mapper() {
this.class1Mapper = new Class1Mapper();
}
public Class2 map(int index, ResultSet rs, StatementContext ctx)
{
Class2 myC2 = new Class2();
class1 = class1Mapper.map(rs,ctx); // use this class1 object
//Do some mapping with other variables of myC2
return myC2;
}
}