diff --git a/zheng-common/pom.xml b/zheng-common/pom.xml index 52b8590c..7d89603e 100644 --- a/zheng-common/pom.xml +++ b/zheng-common/pom.xml @@ -22,6 +22,7 @@ 3.4.2 1.3.1 + 5.0.1 1.3.5 1.0.0 2.10.0 @@ -112,13 +113,11 @@ mybatis-spring ${mybatis-spring.version} - org.mybatis.generator mybatis-generator-core diff --git a/zheng-common/src/main/java/com/zheng/common/base/BaseService.java b/zheng-common/src/main/java/com/zheng/common/base/BaseService.java index 255bc0cc..79f08133 100644 --- a/zheng-common/src/main/java/com/zheng/common/base/BaseService.java +++ b/zheng-common/src/main/java/com/zheng/common/base/BaseService.java @@ -24,6 +24,14 @@ public interface BaseService { List selectByExample(Example example); + List selectByExampleWithBLOBsForStartPage(Example example, Integer pageNum, Integer pageSize); + + List selectByExampleForStartPage(Example example, Integer pageNum, Integer pageSize); + + List selectByExampleWithBLOBsForOffsetPage(Example example, Integer offset, Integer limit); + + List selectByExampleForOffsetPage(Example example, Integer offset, Integer limit); + Record selectFirstByExample(Example example); Record selectFirstByExampleWithBLOBs(Example example); diff --git a/zheng-common/src/main/java/com/zheng/common/base/BaseServiceImpl.java b/zheng-common/src/main/java/com/zheng/common/base/BaseServiceImpl.java index 09f5b539..3daf4a54 100644 --- a/zheng-common/src/main/java/com/zheng/common/base/BaseServiceImpl.java +++ b/zheng-common/src/main/java/com/zheng/common/base/BaseServiceImpl.java @@ -1,5 +1,6 @@ package com.zheng.common.base; +import com.github.pagehelper.PageHelper; import com.zheng.common.db.DataSourceEnum; import com.zheng.common.db.DynamicDataSource; import com.zheng.common.util.SpringContextUtil; @@ -116,6 +117,66 @@ public abstract class BaseServiceImpl implements BaseSe return null; } + @Override + public List selectByExampleWithBLOBsForStartPage(Example example, Integer pageNum, Integer pageSize) { + try { + DynamicDataSource.setDataSource(DataSourceEnum.SLAVE.getName()); + Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass()); + PageHelper.startPage(pageNum, pageSize, false); + Object result = selectByExampleWithBLOBs.invoke(mapper, example); + return (List) result; + } catch (Exception e) { + e.printStackTrace(); + } + DynamicDataSource.clearDataSource(); + return null; + } + + @Override + public List selectByExampleForStartPage(Example example, Integer pageNum, Integer pageSize) { + try { + DynamicDataSource.setDataSource(DataSourceEnum.SLAVE.getName()); + Method selectByExample = mapper.getClass().getDeclaredMethod("selectByExample", example.getClass()); + PageHelper.startPage(pageNum, pageSize, false); + Object result = selectByExample.invoke(mapper, example); + return (List) result; + } catch (Exception e) { + e.printStackTrace(); + } + DynamicDataSource.clearDataSource(); + return null; + } + + @Override + public List selectByExampleWithBLOBsForOffsetPage(Example example, Integer offset, Integer limit) { + try { + DynamicDataSource.setDataSource(DataSourceEnum.SLAVE.getName()); + Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass()); + PageHelper.offsetPage(offset, limit, false); + Object result = selectByExampleWithBLOBs.invoke(mapper, example); + return (List) result; + } catch (Exception e) { + e.printStackTrace(); + } + DynamicDataSource.clearDataSource(); + return null; + } + + @Override + public List selectByExampleForOffsetPage(Example example, Integer offset, Integer limit) { + try { + DynamicDataSource.setDataSource(DataSourceEnum.SLAVE.getName()); + Method selectByExample = mapper.getClass().getDeclaredMethod("selectByExample", example.getClass()); + PageHelper.offsetPage(offset, limit, false); + Object result = selectByExample.invoke(mapper, example); + return (List) result; + } catch (Exception e) { + e.printStackTrace(); + } + DynamicDataSource.clearDataSource(); + return null; + } + @Override public Record selectFirstByExample(Example example) { try { diff --git a/zheng-common/src/main/java/com/zheng/common/base/BaseServiceMock.java b/zheng-common/src/main/java/com/zheng/common/base/BaseServiceMock.java index 86bd6971..ffa2bff9 100644 --- a/zheng-common/src/main/java/com/zheng/common/base/BaseServiceMock.java +++ b/zheng-common/src/main/java/com/zheng/common/base/BaseServiceMock.java @@ -45,6 +45,26 @@ public abstract class BaseServiceMock implements BaseSe return null; } + @Override + public List selectByExampleWithBLOBsForStartPage(Example example, Integer pageNum, Integer pageSize) { + return null; + } + + @Override + public List selectByExampleForStartPage(Example example, Integer pageNum, Integer pageSize) { + return null; + } + + @Override + public List selectByExampleWithBLOBsForOffsetPage(Example example, Integer offset, Integer limit) { + return null; + } + + @Override + public List selectByExampleForOffsetPage(Example example, Integer offset, Integer limit) { + return null; + } + @Override public Record selectFirstByExample(Example example) { return null; diff --git a/zheng-common/src/main/resources/mybatis-config.xml b/zheng-common/src/main/resources/mybatis-config.xml index 773eef31..6fccd258 100644 --- a/zheng-common/src/main/resources/mybatis-config.xml +++ b/zheng-common/src/main/resources/mybatis-config.xml @@ -9,4 +9,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file