我创建从主详细表中的java bean。让我们调用主表A和详细信息表B.当我把它放入一个java bean中时,我有BeanA和BeanB。 BeanA将拥有A表中的所有相关行,并且还将具有基于主键的BeanB(细节表B)的列表集合。所以BeanA看起来像从主详细信息表创建一个Java Bean - 性能比较的问题
class BeanA {
String property1;
String Property2;
List<BeanB> lstpropery; //This is the data of detail table based on the primary key
}
在这个scenerio我使用Spring JDBC来查询表。因此,当我查询表A并遍历结果集并设置BeanA属性时,我还将通过对B表执行查询来设置lst属性。
这样的代码将
String qry = "select * from A';
result = this.queryTemplate.query(qry, obj, new RowMapper(){
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
BeanA bean1= new BeanA();
bean1.setProperty1(rs.getString(1));
bean1.setProperty2(rs.getString(2));
bean1.setLstpropery(callTableB(String primaryKey)); // I see a performance issue here
return bean1;
}
});
有没有更好的方式来做到这一点?
感谢您的答复,我使用Spring的JdbcTemplate,有没有更好的方式来做到这一点使用spirng? –