当前位置: 代码迷 >> Java Web开发 >> ibatis返回的list只有一个值,该如何解决
  详细解决方案

ibatis返回的list只有一个值,该如何解决

热度:375   发布时间:2016-04-17 10:47:09.0
ibatis返回的list只有一个值
person.xml
XML code
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"    "http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMap namespace="person">      <typeAlias alias="phone" type="com.gogoosoft.entity.Person"/>          <select id="findAllPhone" resultClass="phone" remapResults="true">            SELECT * FROM person      </select>  </sqlMap>

DAO
Java code
package com.gogoosoft.dao.impl;import java.sql.SQLException;import java.util.ArrayList;import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;import com.gogoosoft.dao.PersonDao;import com.gogoosoft.entity.Person;import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;import com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate;import com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl;public class PersonDaoImp extends SqlMapClientDaoSupport implements PersonDao{    public ArrayList<Person> getAll() throws SQLException {        ArrayList<Person> list = null;        list = (ArrayList<Person>) this.getSqlMapClientTemplate().queryForList("findAllPhone", null);        return list;    }    }


------解决方案--------------------
没发现什么错误 remapResults="true"去掉试试
还有queryForList("person.findAllPhone", null)最好这么写 带上命名空间
------解决方案--------------------
把SQL在数据库里面执行一下,确认一下有多少数据
  相关解决方案