Map 循环问题。。。

王者天下ii 2013-12-06 05:05:11
代码:


Map<String, Student> obj=studentDaoImpl.getMapStudent();
System.out.println(obj);

for(Map.Entry<String, Student> entry : obj.entrySet()){
System.out.println("key: "+entry.getKey() +"; value: "+ entry.getValue() );
}

错误信息:
{0={id=0, birth=2011-09-02 00:00:00.0, name=李四, score=88}, 2={id=2, birth=2011-09-02 00:00:00.0, name=李四, score=88}}
Exception in thread "main" java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
at com.iflytek.test.TestIbatis.main(TestIbatis.java:57)


数据列:

id NUMBER not null,
name VARCHAR2(30),
birth DATE,
score NUMBER

...全文
167 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
王者天下ii 2013-12-06
  • 打赏
  • 举报
回复
引用 1 楼 rui888 的回复:
BigDecimal 转 string TestIbatis.java:57)
/*Map<Integer,String> map = new LinkedHashMap<Integer,String>(); map.put(1, "星期一"); map.put(2, "星期二"); map.put(3, "星期三"); map.put(4, "星期四"); map.put(5, "星期五"); map.put(6, "星期六"); map.put(7, "星期日"); for(Map.Entry<Integer, String> entry: map.entrySet()) { System.out.print(entry.getKey() + ":" + entry.getValue() + "\t"); }*/ 我这样写就没问题,想不通啊,能告诉我这有什么区别和怎么处理吗?
王者天下ii 2013-12-06
  • 打赏
  • 举报
回复
引用 2 楼 chenxinhui741 的回复:
用itearter遍历map的键,通过键获取student对象,进行遍历
那样写,跟我这样写应该都一样的吧
王者天下ii 2013-12-06
  • 打赏
  • 举报
回复
引用 1 楼 rui888 的回复:
BigDecimal 转 string TestIbatis.java:57)
我不知道怎么处理
吸尘器 2013-12-06
  • 打赏
  • 举报
回复
用itearter遍历map的键,通过键获取student对象,进行遍历
tony4geek 2013-12-06
  • 打赏
  • 举报
回复
BigDecimal 转 string TestIbatis.java:57)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧