根据 spring-boot 应用程序中 RowCallBackHandler 的输出在 DTO 对象中动态设置属性

问题描述 投票:0回答:0

下面是我的 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.
}
java spring-boot reflection jdbctemplate
© www.soinside.com 2019 - 2024. All rights reserved.