下面是我的 DTO 对象,我正在根据用户选择构建 SQL 查询。因此,它可以具有 DTO 类中的任何一组属性。
Eg: (Any combination)
select res.name from Response res ;
select res.name, res.city from Response res ;
....
select res.* from Response res ;
public class Response{
@CloumnName("NAME")
private String name;
@CloumnName("CITY")
private String city;
@CloumnName("AMOUNT")
private BigDecimal amount;
...
@CloumnName("PRICE")
private BigDecimal price;
}
List<String> userSelectionList=getUserSelectionList();
String sql=generateSqlBasedOnUserSelection();
jdbcTemplate.query(sql,new RowCallBackHandler(){
public void processRows(ResultSet resultSet) throws SqlException{
//Now how can construct the Response object Dynamically based on the columns available in the ResultSet.It should set value for available properties. Rest can be null.
}