public void expertClean() {
QueryWrapper<CleanExpert> cleanExpertQueryWrapper = new QueryWrapper<>();
LambdaQueryWrapper<CleanExpert> cleanWrapper = cleanExpertQueryWrapper.lambda().isNotNull(CleanExpert::getId);
List<CleanExpert> cleanExperts = cleanExpertMapper.selectList(cleanWrapper);
cleanExperts.forEach(x -> {
int province = x.getNativePlace().indexOf("省");
String result = substring(x.getNativePlace(), 0,province+1);
System.out.println(result);
Object o = redisTemplate.opsForHash().get("dic:operation:cityNameKey", result);
if (o != null) {
Long degreeId = Long.parseLong(o.toString());
if (degreeId != null) {
Connection connection = getConnection();
try {
//update clean_data set 'major_subject' = ? where id = ?
String sql = "update clean_data set province = ? where id = ?";
PreparedStatement pstmt = connection.prepareStatement(sql, Statement.NO_GENERATED_KEYS);
pstmt.setLong(1, degreeId);
pstmt.setString(2, x.getId());
pstmt.executeUpdate();
connection.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
System.out.println(degreeId);
}
}
});
}
pom 引入:
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>4.2.3</version> </dependency>