我有一个用例,其中除了通常的where子句条件参数外,select查询和table_name中的列还需要动态。我的查询如下所示:
从:tableName 中选择id,entity_id,:columnName ,开始日期,结束日期,其中entity_id = :entityId
现在我如何编写我的mapRow()方法,因为我的 columnName 也是动态的?
public class EntityResultsetMapper implements RowMapper<EntityResultset>{
@Override
public EntityResultset mapRow(ResultSet rs, int rowNum) throws SQLException {
EntityResultset EntityResultset = new EntityResultset();
EntityResultset.setId(rs.getString("ID"));
EntityResultset.setIssuerId(rs.getString("entity_id"));
//How to pass column here?????
EntityResultset.setFactorId(rs.getString("How do I pass column to fetch from"));
EntityResultset.setStartDate(rs.getDate("start_date"));
EntityResultset.setEndDate(rs.getDate("end_date"));
return EntityResultset;
}
}
还是应该使用rowMapper代替其他东西?