Java代码
import tk.mybatis.mapper.entity.Example;
private void handleByBatch() { List<String> personIdPreList = personInfoMapper.getPersonIdPreList(); personIdPreList = personIdPreList.stream().distinct().sorted().collect(Collectors.toList()); if (CollectionUtils.isEmpty(personIdPreList)) { return; } Iterator<String> iterator = personIdPreList.iterator(); String beginIdPre = iterator.next(); while (iterator.hasNext()) { String endIdPre = iterator.next(); handlePreIdData(beginIdPre, endIdPre); beginIdPre = endIdPre; } }
private void handlePreIdData(String beginIdPre, String endIdPre) { Example example = new Example(javaBean.class);//javaBean为实体类 criteria = (); ("id", beginIdPre); ("id", endIdPre); List<javaBean> list = (example); handleByPersonInfo(list); }
- 1
- 2
- 3
Javabean
import javax.persistence.Column; import javax.persistence.Id; import javax.persistence.Table; @Table(name = "tb_test") public class javaBean { @Id private String id; @Column(name = "name") private String name; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
- 1
xml
<select id="getPersonIdPreList" resultType=""> select DISTINCT(left(id,3)) pre from tb_person_info </select>
- 1
思路,取ID前三位,我做的时候500多万数据,分成了4000多,查的很快