建议:实体类一定要用工具自动生成,避免手误!
原因:对象的属性名和表的列名不同,实例:
private String metaIsManage;//是否管理项
@Column(name = "MATE_IS_MANAGE")
public String getMetaIsManage() {
return metaIsManage;
}
public void setMetaIsManage(String metaIsManage) {
this.metaIsManage = metaIsManage;
}注意上面代码中属性名和列名字母顺序不同,导致使用如下代码查询出来的metaIsManage属性总是为nullString sql = "SELECT * FROM el_table_column " +
"WHERE table_Id = ? " +
"ORDER BY column_order ASC, catalog_table_addtime DESC";
return jdbc.query(sql, new Object[]{tableId}, new BeanPropertyRowMapper(ElTableColumn.class));跟踪spring的源码发现:
mappedFields的hashMap中的内容如下:
{mate_id=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=mateId],
catalogtableiscodeset=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogTableIscodeset],
columndesc=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnDesc],
columnname=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnName],
mateno=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=mateNo],
columnid=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnId],
column_name=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnName],
metaismanage=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=metaIsManage],
catalog_pk=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogPk],
isshow=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=isShow],
catalogitemid=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogItemId],
catalogtablecodesetpk=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogTableCodesetPk],
catalog_table_codeset_pk=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogTableCodesetPk],
length=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=length],
column_order=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnOrder],
catalog_table_modifytime=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogTableModifytime],
meta_is_manage=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=metaIsManage],
column_type=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnType],
catalogitemno=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogItemNo],
meta_column_format=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=metaColumnFormat],
column_desc=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnDesc],
column_id=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnId],
table_id=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=tableId],
nullable=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=nullable],
metacolumnformat=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=metaColumnFormat],
iskey=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=isKey],
catalogtablemodifytime=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogTableModifytime],
catalogpk=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogPk],
is_key=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=isKey],
is_show=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=isShow],
catalog_item_id=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogItemId],
tableid=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=tableId],
catalog_table_addtime=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogTableAddtime],
catalog_item_no=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogItemNo],
mate_no=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=mateNo],
catalog_table_iscodeset=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogTableIscodeset],
mateid=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=mateId],
catalogtableaddtime=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=catalogTableAddtime],
columnorder=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnOrder],
columntype=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=columnType]}所以根据mate_is_manage为key获取value自然获取不到! 建议:实体类一定要用工具自动生成,避免手误!
版权声明:本文为ljj2312原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。