我在 Java 中有这个存储过程调用:
@Autowired
public ScoreDao(DataSource dataSource) {
setDataSource(dataSource);
mScoreStoredProcedure = new ScoreStoredProcedure(dataSource);
}
public List<Score> loadAllScore(String pUsername, String pUUID, int pLimit) {
return mScoreStoredProcedure.execute(pUsername, pUUID, pLimit);
}
private class ScoreStoredProcedure extends StoredProcedure {
private static final String SPROC_NAME = "loadUserScore";
public ScoreStoredProcedure(DataSource datasource) {
super(datasource, SPROC_NAME);
declareParameter(new SqlReturnResultSet("#result-set-2", mScoreMapper));
declareParameter(new SqlParameter("vusername", Types.VARCHAR));
declareParameter(new SqlParameter("vuuid", Types.VARCHAR));
declareParameter(new SqlParameter("vlimit", Types.INTEGER));
compile();
}
@SuppressWarnings("unchecked")
public List<Score> execute(String pUsername, String pUUID, int pLimit){
Map<String,Object> lAllScoreResult = super.execute(pUsername, pUUID, pLimit);
List<Score> lAllScore = ((List<Score>)lAllScoreResult.get("#result-set-2"));
return lAllScore;
}
}
这个映射器类:
public class ScoreMapper implements RowMapper<Score> {
private String suffix = "";
@Autowired
private ScoreCreator scoreCreator;
@Autowired
private QuestionMapper questionMapper;
public ScoreMapper(String pSuffix) {
suffix = pSuffix;
}
public Score mapRow(ResultSet rs, int rowNum) throws SQLException {
Score lScore = scoreCreator.createScore(rs.getLong(suffix+"id"),
rs.getTimestamp(suffix+"stempel"), rs.getString(suffix+"username"),
rs.getInt(suffix+"points"), rs.getInt(suffix+"level"),
rs.getString(suffix+"comment"),
questionMapper.mapRow(rs, rowNum), rs.getString(suffix+"uuid"));
return lScore;
}
}
我遇到的问题是 my 的结果StoredProcedure
永远不会转换为List<Score>
.
相反,它包含一个LinkedCaseInsensitiveMap<V>
. 每个条目涵盖数据库中的一个值。
映射器通过 Spring 正确连接。
简要地说:我期望结果是List<Score>
. 我想我用代码中显示的方法来处理这个问题。如何将结果直接投射到我的List<Score>
?
我按照本教程http://www.jtmelton.com/2007/10/30/using-springs-storedprocedure-and-rowmapper-mechanisms/
你能帮我找出问题吗?