/**
* 一行结果集中包含了两张表的列
* 使用MapHandler来处理
* 1. 把结果集封装到map中
* 2. 使用map生成Person对象
* 3. 使用map生成address对象
* 4. 把两个实体对象建立关系
* @throws SQLException
*/
@Test
public void testQuery6() throws SQLException {
String sql = "SELECT * FROM t_person p, t_address a WHERE p.aid=a.aid AND p.pid=?";
QueryRunner qr = new TxQueryRunner();
/*
* 1. 得到Map
*/
Map map = qr.query(sql, new MapHandler(), "aaa");
/*
* 2. 把Map中部分数据封装到Person中
*/
Person p = CommonUtils.toBean(map, Person.class);
/*
* 3. 把Map中部分数据封装到Address中
*/
Address addr = CommonUtils.toBean(map, Address.class);
/*
* 4. 建立两个实体的关系
*/
p.setAddress(addr);
System.out.println(p);
}
小工具(4):.多表结果集映射,以及log4j配置c3p0日志信息
最新推荐文章于 2023-04-17 23:32:56 发布