这个 RowMapper 的错误在哪里
where is the error in this RowMapper
我有这个请求 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)
看看documentation。行映射器为单行映射对象。
This method should not call next() on the ResultSet; it is only supposed to map values of the current row.
所以您的 return 类型应该是 IWsResponse 而不是 List。此外,您必须只映射当前行。不是全部。
我有这个请求 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)
看看documentation。行映射器为单行映射对象。
This method should not call next() on the ResultSet; it is only supposed to map values of the current row.
所以您的 return 类型应该是 IWsResponse 而不是 List。此外,您必须只映射当前行。不是全部。