简体   繁体   中英

what is the best way to select hundred of parameters with spring data

I need to select a hundred of parameters from database then return it in a DTO to create an excel file.

I'm using spring data, i think have two solutions:

  1. using multiselect method then define a constructor in DTO with all parameters(the number of parameter is more than 100)

  2. using multiselect method and map the array (Object[]) returned to a DTO=>mapping is hard to implement and not scalable.

Do you have any other idea please?

Thank you.

If you have more than 100 parameters, that's a lot for constructor. How do you get these parameters? maybe you can use a (key,value) map instead?

If the model is complicated then maybe you can use plain old JDBC? Then you can easily put these parameters into the query.

Plain old ResultSet it is quite easy to work with, you can get each row and column one after another and check their type, you can build the Excel file line by line then. Skip instantiating the DTO.

I agree with the sentiment of Krzysztof Cichocki. Don't use JPA for this. JPA is for loading an object graph, modifying it and persisting the changes again. It generates to much overhead for things like generating a report.

Instead of using plain JDBC, I recommend using JdbcTemplate or NamedParameterJdbcTemplate .

The methods taking a RowCallBackHandler seem the right choice for your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM