需求:
需要一個(gè)按鈕,每次執(zhí)行的時(shí)候,調(diào)接口刷新數(shù)據(jù)庫(kù)表中的數(shù)據(jù):
刷新條件:
如果接口獲取的數(shù)據(jù)和數(shù)據(jù)庫(kù)表的數(shù)據(jù)完全一致則不刷新,如果不一致,則新增數(shù)據(jù);文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-608189.html
// 實(shí)現(xiàn)接口層
@Override
public Result addInfo(Map<String, Object> paramMap) {
List<Map<String,String>> reg = getRegionInfo(); // 接口獲取的數(shù)據(jù)
List<Map<String,String>> list = xxxMapper.selectQuestRegAll(); // 數(shù)據(jù)庫(kù)查詢的數(shù)據(jù)
Iterator<Map<String, String>> iterator = reg.iterator();
while (iterator.hasNext()){
Map<String, String> next = iterator.next();
String name = String.valueOf(next.get("name"));
String code = String.valueOf(next.get("code"));
Iterator<Map<String, String>> iterator2 = list.iterator();
while (iterator2.hasNext()){
Map<String, String> next2 = iterator2.next();
String regionName = String.valueOf(next2.get("name"));
String RegionCode = String.valueOf(next2.get("code"));
// 根據(jù)條件刪除數(shù)據(jù):
if(name.equals(regionName) && code.equals(RegionCode)){
iterator.remove();
}
}
}
// 如果reg有數(shù)據(jù),則新增;
if(reg.size() > 0){
xxxMapper.addInfo(reg);
}
// Mapper層
void addInfo(List<Map<String, String>> paramList);
// 持久化層
<!-- 數(shù)據(jù)刷新 -->
<insert id="addInfo" parameterType="java.util.List">
<foreach collection="list" item="customer" index="index" separator=";">
INSERT IGNORE INTO xxx_form_data
<foreach collection="customer.entrySet()" index="key" separator="," open="(" close=")">
${key}
</foreach>
VALUES
<foreach collection="customer.entrySet()" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</foreach>
</insert>
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-608189.html
到了這里,關(guān)于<Java Iterator> 迭代器Iterator雙層循環(huán) 案例分享的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!