我有此请求SQL
:
private List<IWsResponse> getBPartnerDetails(String valueNetwork, String reportLevel2) {
JdbcTemplate tm = new JdbcTemplate(ds.getDataSource());
StringBuffer sql = new StringBuffer("SELECT * FROM XRV_BPARTNERDETAILS order by BPartner_ID");
ArrayList<Object> params = new ArrayList<Object>();
response = tm.query(sql.toString(), new BPartnerMapper());
return response;
}
我像这样创建一个新的RowMapper(BPartnerMapper)
public class BPartnerMapper implements RowMapper<IWsResponse> {
@Override
public List<IWsResponse> mapRow(ResultSet rs, int rowNum) throws SQLException {
List<IWsResponse> bps = new ArrayList<IWsResponse>();
while (rs.next()) {
bp = new BPartner();
bp.setBPartnerValue(rs.getString("BPartnerValue"));
//adress
adr = new Adress();
adr.setBPartnerLocation_ID(BPartner_Location_ID);
bp.getAdress().add(adr);
//user
usr = new User();
usr.setUser_ID(User_ID);
bp.getUsers().add(usr);
bps.add(bp)
}
return bps;
}
Class BPartner
public class BPartner implements IWsResponse {
private String BPartnerValue;
private ArrayList<Adress> adress = new ArrayList<Adress>();
private ArrayList<User> users = new ArrayList<User>();
}
所以我得到了这个错误
The return type is incompatible with RowMapper<IWsResponse>.mapRow(ResultSet, int)
答案 0 :(得分:0)
看看documentation。行映射器映射单个行的对象。
此方法不应调用ResultSet上的next();它只应映射当前行的值。
所以你的返回类型应该是IWsResponse而不是List。此外,您只能映射当前行。不是全部。