在SSH中,Dao层:
List result = getSession().createSQLQuery("SELECT studentId,studentPassword From student WHERE studentId=2014041883;").list();
我想获得result中 studentId 和 studentPassword的值(数据库中的值)
用log.debug(result.get(0));打印出现错误
打印出:[Ljava.lang.Object;@47990d6e
求教怎么获得值
如果你个这个sql取得是一条数据的话最好用map
Map result =
getSession().createSQLQuery("SELECT studentId,studentPassword From student WHERE studentId=2014041883;").setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).uniqueResult();
result.get("studentId") and result.get("studentPassword") 就可以获取你想要的值了
如果你是多条的话
List> result =getSession().createSQLQuery("SELECT studentId,studentPassword From student WHERE studentId=2014041883;").setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
for(Map map :result){
map.get("studentId") and map.get("studentPassword") 就可以获取你想要的值了
}
result.get(0)获得的应该是一个studentId,studentPassword 两个元素的数组,或者是保护studentId,studentPassword 两个属性的对象。我没用过这种方法,所以我不确定,最近去debug调试吧。
还有一种方法,把返回结果放到map中:
getSession().createSQLQuery("SELECT studentId,studentPassword From student WHERE studentId=2014041883;").setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).uniqueResult()
这样得到一个map,直接get就可以获得值了
如果用别名,还要加addScalar(别名);