话不多说,直接上代码
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.batch.MyBatisCursorItemReader;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.database.JdbcPagingItemReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class xxxxReader {
@Autowired
SqlSessionFactory sqlSessionFactory;
@Bean("reader")
@StepScope
public MyBatisCursorItemReader<xxxx> reader(@Value("#{jobParameters[date]}") String date){
MyBatisCursorItemReader<xxx> reader = new MyBatisCursorItemReader<xxxx>();
//这个map是mybatis的参数
Map<String , Object> map = new HashMap<String , Object>();
map.put("stat" , "A");
map.put("date" , date);
reader.setQueryId("com.xx.xxx..dao.xxxxxMapper.queryxxx");
reader.setSqlSessionFactory(sqlSessionFactory);
reader.setParameterValues(map);
return reader;
}
}
dao怎么写,这里就省了。。