我现在要建立一个实体类,这个类对应于数据库里面的一个表。这个表有大约30多个字段。但是表中大部分的记录只用到其中一小部分字段。现在我考虑了两种方案:第一种,也就是通常的方法,每个字段对应一个类属性,那么这个类就需要有30多个域第二种,类只维护一个Map。在实例化时,只将用到的字段的key-value对插入到Map中。我以为这样看上去比较省空间。但是究竟哪个综合性能更高一点?
解决方案 »
- JAVA MAIL 使用POP3 接受邮件如何判断邮件是否已读
- 前辈指点:俺新手,请问J2EE框架中 integer变量如何赋初值?现在报空指针错误。。。
- javascript时间处理问题
- 此课题为了解决软件开发中的业务更改繁琐的问题(java)
- 关于ehcache缓存的使用问题,有点不解。第一次用缓存框架
- structs配置数据源
- [求助]Spring中关于静态常量的配置
- Cannot use JVM pre-1.4 access bug workaround die to restrictive security manager
- Document doc = builder.build(url.openStream());url老是找不到 DBConfig.xml中呢?请问如何找到 WEB_INF/class 目录下的 DBConfig.xml
- 问一个很简单的问题????????????
- 有学过Ibatis的进来帮下忙!
- STRUTS2中json的一个问题
Map本身也是一种系统开销
Map本身也是一种开销
Map本身也是一种开销
另一方面,及时建立完整的属性映射,你的select语句也没必要每次都select *
用多少select多少就是了,只映射使用到的字段,其他留null不就可以了
private int rowNum;
private int colNum;
private Object data;
DataNode nextRow;
DataNode nextCol;
public int getRowNum() {
return rowNum;
}
public void setRowNum(int rowNum) {
this.rowNum = rowNum;
}
public int getColNum() {
return colNum;
}
public void setColNum(int colNum) {
this.colNum = colNum;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public DataNode getNextRow() {
return nextRow;
}
public void setNextRow(DataNode nextRow) {
this.nextRow = nextRow;
}
public DataNode getNextCol() {
return nextCol;
}
public void setNextCol(DataNode nextCol) {
this.nextCol = nextCol;
}
public DataNode() {
}
public DataNode(int rowNum, int colNum, Object data) {
this.rowNum = rowNum;
this.colNum = colNum;
this.data = data;
}
}获取数据时,先从左分支找到对应行(nextRow),然后从右分支(nextCol)把该行不为空的数据读出。PS:关于稀疏矩阵在《数据结构与算法》的课本里有详细介绍,鄙人这里就不赘述了。