Spring的JdbcTemplate从数据库中获取对象属性总为null
来源:互联网 发布:m1卡读写软件 编辑:程序博客网 时间:2024/06/06 03:21
建议:实体类一定要用工具自动生成,避免手误!
原因:对象的属性名和表的列名不同,实例:
private String metaIsManage;//是否管理项@Column(name = "MATE_IS_MANAGE")public String getMetaIsManage() {return metaIsManage;}public void setMetaIsManage(String metaIsManage) {this.metaIsManage = metaIsManage;}注意上面代码中属性名和列名字母顺序不同,导致使用如下代码查询出来的metaIsManage属性总是为null
String 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自然获取不到!
建议:实体类一定要用工具自动生成,避免手误!
阅读全文
0 0
- Spring的JdbcTemplate从数据库中获取对象属性总为null
- hibernate中获取关联属性为null的方式
- 数据库中时间字段为null,获取数据库数据映射到类,类中相应的属性的值是null还是时间默认值
- spring 在Thread中注入@Resource失败,总为null的解决方案
- 验证对象中属性是否为null
- 多线程中引入Spring自动注入的对象为null
- 在datagrid中,IE浏览器报错:SCRIPT5007: 无法获取属性“rowspan”的值: 对象为 null 或未定义
- JdbcTemplate 从数据库中获取数值型数据需要转换
- SCRIPT5007: 无法获取属性“getElementsByTagName”的值: 对象为 null 或未定义 的解决方案
- SCRIPT5007: 无法获取属性“ui”的值: 对象为 null 或未定义
- SCRIPT5007: 无法获取属性“getElementsByTagName”的值: 对象为 null 或未定
- Ext.net GridPanel Erro:无法获取属性“proxy”的值:对象为null或未定义
- SCRIPT5007:无法获取属性“show”的值,对象为null或未定义
- baidumap SCRIPT5007: 无法获取属性“minZoom”的值: 对象为 null 或未定义
- 无法获取属性“getContext”的值: 对象为 null 或未定义
- echarts 无法获取属性“getAttribute”的值: 对象为 null 或未定义 错误解决方法
- 调试出错:无法获取属性"parentNode"的值:对象为null或未定义
- easyui datagrid报 SCRIPT5007: 无法获取属性“length”的值: 对象为 null 或未定义
- 第997期机器学习日报(2017-06-11)
- 简单实现 BroadcastReceiver 回调
- 第四周项目3.3—判断是否为递增链表
- 第998期机器学习日报(2017-06-12)
- 第999期机器学习日报(2017-06-13)
- Spring的JdbcTemplate从数据库中获取对象属性总为null
- 第1000期机器学习日报(2017-06-14)
- 第1001期机器学习日报(2017-06-15)
- radio选中
- Python若干高级特性
- 第1005期机器学习日报(2017-06-19)
- Mysql,姓名按笔画排序
- 第1003期机器学习日报(2017-06-17)
- 第1004期机器学习日报(2017-06-18)