diff --git a/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java b/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java index 5059b33..2033a8e 100644 --- a/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java +++ b/src/main/java/com/telpo/dipperposition/mapper/ProvinceInfoMapper.java @@ -1,14 +1,9 @@ package com.telpo.dipperposition.mapper; -import com.telpo.dipperposition.annotation.MongoSwitch; -import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; -import db.BaseMongoDbDao; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; -import java.util.List; - /** * @program: ProvinceInfoMapper * @description: 省份位置记录mapper diff --git a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java index b47baed..deb0626 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java @@ -5,16 +5,19 @@ import com.telpo.dipperposition.entity.mongo.IpProvinceEntity; import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity; import com.telpo.dipperposition.mapper.IpProvinceMapper; import com.telpo.dipperposition.service.IpProvinceService; +import jdk.nashorn.internal.runtime.options.Option; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import tools.BeanTools; import java.util.List; +import java.util.Optional; /** * @program: DataPushServer @@ -56,15 +59,11 @@ public class IpProvinceServiceImpl implements IpProvinceService { try { IpProvinceEntity query = new IpProvinceEntity(); query.setIp(ipAddress); - Example example = Example.of(query); - PageRequest pageable = PageRequest.of(0, 1); - Page data = ipProvinceMapper.findAll(example, pageable); - if (CollectionUtil.isNotEmpty(data.getContent())) { - List records = BeanTools.copyList(data.getContent(), IpProvinceEntity.class); - return records.get(0); - } else { - return null; - } + //忽略_class属性,不参与查询 + ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class"); + Example example = Example.of(query, matcher); + Optional data = ipProvinceMapper.findOne(example); + return data.get(); } catch (Exception e) { log.error("获取IP省份异常:", e); return null; diff --git a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java index 6ccb38a..668f2ad 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/ProvinceInfoServiceImpl.java @@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -57,15 +58,11 @@ public class ProvinceInfoServiceImpl implements IProvinceInfoService { try { ProvinceInfoEntity query = new ProvinceInfoEntity(); query.setProvince(provicne); - Example example = Example.of(query); - PageRequest pageable = PageRequest.of(0, 1); - Page data = provinceInfoMapper.findAll(example, pageable); - if (CollectionUtil.isNotEmpty(data.getContent())) { - List records = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class); - return records.get(0); - } else { - return null; - } + //忽略_class属性,不参与查询 + ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class"); + Example example = Example.of(query, matcher); + Optional data = provinceInfoMapper.findOne(example); + return data.get(); } catch (Exception e) { log.error("获取省份异常:", e); return null;