i've already seen a lot of tutorials and spring material but i have found only examples that contains a simple object in the ItemWriter.
For example...
@Bean
JdbcBatchItemWriter<Student> writer = new JdbcBatchItemWriter<>();
writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Student>());
writer.setItemPreparedStatementSetter(new ItemPreparedStatementSetter<Student>(){
@Override
public void setValues(Student student, PreparedStatement ps) throws SQLException {
ps.setLong(1,student.getStudentCode());
ps.setObject(2,student.getStudentGrade());
}});
writer.setSql(QUERY_STUDENT_GRADE_INSERT);
writer.setDataSource(dataSource);
return writer;
in my actual scenario i must write a Map that contains a key and a value like:
Map<KeyObject,Long>
But i have no idea how to code something that be able to insert all the content that i've received in my Map.
There's another question...
When i process certain number of items i need to store this data in the database, but the previous content stay in my collection, that way... how can i clean the map content after write ?
The solution was replace my Map for a List
I'm just using lambda to filter the objects in the list and writing them through the common itemWriter.
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.