Error- Collection <object>无法转换为List <class> </class> </object>

时间:2014-01-27 11:36:29

标签: java spring-mvc stored-procedures

我正在学习在java中使用存储过程。之前我使用过JDBC模板,我能够从数据库中获取值。 现在我有一个错误:Collection Object无法转换为List Class

有什么方法可以将Collection(Object)转换为List(Class)?

是我的模特课

我的存储过程类

public class ListRegistration extends StoredProcedure {
     @Autowired
    private DataSource dataSource;
    private static final String SCHEMA_NAME = "ehr";
    private static final String SPROC_NAME = "ehr.usp_ListRegistration";

    public DataSource getDataSource() {
        return dataSource;
    }

    public ListRegistration(DataSource dataSource) {
        super(dataSource, SPROC_NAME);
        declareParameter(new SqlReturnResultSet("rs", new BeanPropertyRowMapper(Patient.class)));
       declareParameter(new SqlParameter("LimitRows", Types.INTEGER));
        compile();
    }
public List<Patient> spExecute(Integer LimitRows)
{

  Map<String, Object> registrationResult=new HashMap<String,Object>();
     registrationResult = super.execute(LimitRows);

  List<Patient> patientList = new ArrayList<Patient>;
 patientList = registrationResult.values();
      return patientList;
}

}

List<Patient> patientList = new ArrayList<Patient>;
     patientList = registrationResult.values();

这是我收到错误的地方。

在我的实施课中我有

   public List<Patient> getPatient() {
    System.out.println("============================ Will Fetch Values ");
    List<Patient> patientList = new ArrayList<Patient>();
     int t=100;
      patientList=listRegistration.spExecute(100);
      return patientList;
    }

1 个答案:

答案 0 :(得分:0)

values()返回一个Set,而不是List。

你可以做的是:

 List<Patient> patients = new ArrayList(registrationResults.values());

这将创建一个新列表并用返回的密钥填充它。

为什么你真的需要这样做呢?如果您只使用values作为CollectionSet,则代码效率会更高。

相关问题