JDBCTempalte RowMapper读取postgres表中的jsonb列



我正在使用JDBCTemplate读取Postgres表,该表具有以下模式:

orderid|order_name|features|extra_features|

orderid:integer
order_name:text
features:josnb
extra_features:jsonb

订单DTO:

public class Order{
private Integer orderid;
private String orderName;
List<Features> features;
List<ExtraFeatures> extraFeatures;
....
getter & setter   
}

功能DTO:

public class Features{
private String featureName:
private String featureValuel
}

现在,在执行SELECT*FROM public.orders查询时,我正在编写rowMapper,如下所示:jdbcTemplate.query("SELECT * FROM public.orders", new OrderRowMapper())

RowMapper

public class OrderRowMapper implements RowMapper<Order>{
@Override
public Order mapRow(ResultSet rs, int rowNum) throws SQLException{
Order order = new Order();
order.setOrderid(rs.getInt("orderid"));
order.setFeatures()// how to read jsonbcolumn?
}
}

我可以设置除jsonb列之外的所有值,我不知道如何实现RowMapper,请帮助。


public class OrderRowMapper implements RowMapper<Order>{
private ObjectMapper mapper = new ObjectMapper();
@Override
public Order mapRow(ResultSet rs, int rowNum) throws SQLException{
List<Features> features = objectMapper
.readValue(rs.getString("features"), 
new TypeReference<List<Features>>(){});
Order order = new Order();
order.setOrderid(rs.getInt("orderid"));
order.setFeatures()// how to read jsonbcolumn?
}
}

相关内容

  • 没有找到相关文章

最新更新