日期:2014-05-17  浏览次数:20750 次

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在数据库里面执行一下,确认一下有多少数据