Explorar el Código

1.修复分页查询
2.修改代码生成模板

1 hace 1 mes
padre
commit
173b2dc389

+ 8 - 7
imwork-windows/imwork-silos/src/main/java/top/imwork/window/silos/service/impl/ContentsServiceImpl.java

@@ -1,13 +1,12 @@
 package top.imwork.window.silos.service.impl;
 
 import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 import jakarta.annotation.Resource;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 import top.imwork.commons.core.constants.Constants;
@@ -22,6 +21,7 @@ import top.imwork.window.silos.service.IContentsService;
 import top.imwork.window.silos.convert.ContentsConvert;
 
 import java.util.Date;
+import java.util.List;
 
 @Service("contentsService")
 public class ContentsServiceImpl extends ServiceImpl<ContentsDao,Contents> implements IContentsService {
@@ -114,16 +114,17 @@ public class ContentsServiceImpl extends ServiceImpl<ContentsDao,Contents> imple
             queryWrapper.apply("update_time <= '" + contentsListDTO.getUpdateEndTime() + "'");
         }
 
-        Page<Contents> page = new Page<>(contentsListDTO.getPageNo(), contentsListDTO.getPageRows());
+
         PageHelper.startPage(contentsListDTO.getPageNo(), contentsListDTO.getPageRows());
-        IPage<Contents> iPage = contentsDao.queryPage(page, queryWrapper);
+        List<Contents> list = contentsDao.selectList(queryWrapper);
+        PageInfo<Contents> pageInfo = new PageInfo<>(list);
 
         ContentsResultBO resultBO = new ContentsResultBO();
         resultBO.setPageNo(contentsListDTO.getPageNo());
         resultBO.setPageRows(contentsListDTO.getPageRows());
-        resultBO.setPageCount((int) iPage.getPages());
-        resultBO.setTotalRows((int) iPage.getTotal());
-        resultBO.setDataList(ContentsConvert.contentsListToContentsBOList(iPage.getRecords()));
+        resultBO.setPageCount(pageInfo.getPages());
+        resultBO.setTotalRows((int) pageInfo.getTotal());
+        resultBO.setDataList(ContentsConvert.contentsListToContentsBOList(list));
         resultBO.setParams(contentsListDTO);
 
         return resultBO;

+ 8 - 9
imwork-windows/imwork-silos/src/main/java/top/imwork/window/silos/service/impl/InfoServiceImpl.java

@@ -1,12 +1,12 @@
 package top.imwork.window.silos.service.impl;
 
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 import jakarta.annotation.Resource;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 import top.imwork.commons.core.constants.Constants;
@@ -164,16 +164,15 @@ public class InfoServiceImpl extends ServiceImpl<InfoDao, Info> implements IInfo
         if (!StringUtils.isEmpty(infoListDTO.getUpdateEndTime())) {
             queryWrapper.apply("update_time <= '" + infoListDTO.getUpdateEndTime() + "'");
         }
-
-        Page<Info> page = new Page<>(infoListDTO.getPageNo(), infoListDTO.getPageRows());
-        IPage<Info> iPage = infoDao.queryPage(page, queryWrapper);
-
+        PageHelper.startPage(infoListDTO.getPageNo(), infoListDTO.getPageRows());
+        List<Info> list = infoDao.selectList(queryWrapper);
+        PageInfo<Info> pageInfo = new PageInfo<>(list);
         InfoResultBO resultBO = new InfoResultBO();
         resultBO.setPageNo(infoListDTO.getPageNo());
         resultBO.setPageRows(infoListDTO.getPageRows());
-        resultBO.setPageCount((int) iPage.getPages());
-        resultBO.setTotalRows((int) iPage.getTotal());
-        resultBO.setDataList(InfoConvert.infoListToInfoBOList(iPage.getRecords()));
+        resultBO.setPageCount(pageInfo.getPages());
+        resultBO.setTotalRows((int) pageInfo.getTotal());
+        resultBO.setDataList(InfoConvert.infoListToInfoBOList(list));
         resultBO.setParams(infoListDTO);
 
         return resultBO;

+ 4 - 0
imwork-windows/imwork-silos/src/main/resources/application.yml

@@ -73,9 +73,13 @@ mybatis-plus:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 
 pagehelper:
+  #  数据库方言
   helperDialect: mysql
+  #  页码合理化
   reasonable: true
+  #  支持接口参数
   supportMethodsArguments: true
+  #  控制台输出查询sql
   params: count=countSql
 upload:
   path: ./uploads/

+ 8 - 7
imwork-windows/imwork-silos/src/main/resources/moudle/ServiceImpl.ftl

@@ -1,12 +1,12 @@
 package ${package}.service.${moduleName}.impl;
 
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 import jakarta.annotation.Resource;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 import ${commonsPath}.commons.core.utils.StringUtils;
@@ -90,15 +90,16 @@ public class ${className}ServiceImpl extends ServiceImpl<${className}Dao,${class
             queryWrapper.apply("update_time <= '" + ${classname}ListDTO.getUpdateEndTime() + "'");
         }
 
-        Page<${className}> page = new Page<>(${classname}ListDTO.getPageNo(), ${classname}ListDTO.getPageRows());
-        IPage<${className}> iPage = ${classname}Dao.queryPage(page, queryWrapper);
+        PageHelper.startPage(${classname}ListDTO.getPageNo(), ${classname}ListDTO.getPageRows());
+        List<${className}> list = ${classname}Dao.selectList(queryWrapper);
+        PageInfo<${className}> pageInfo = new PageInfo<>(list);
 
         ${className}ResultBO resultBO = new ${className}ResultBO();
         resultBO.setPageNo(${classname}ListDTO.getPageNo());
         resultBO.setPageRows(${classname}ListDTO.getPageRows());
-        resultBO.setPageCount((int) iPage.getPages());
-        resultBO.setTotalRows((int) iPage.getTotal());
-        resultBO.setDataList(${className}Convert.${classname}ListTo${className}BOList(iPage.getRecords()));
+        resultBO.setPageCount(pageInfo.getPages());
+        resultBO.setTotalRows((int) pageInfo.getTotal());
+        resultBO.setDataList(${className}Convert.${classname}ListTo${className}BOList(list));
         resultBO.setParams(${classname}ListDTO);
 
         return resultBO;

+ 12 - 9
imwork-windows/imwork-silos/src/main/resources/templates/cms/book/contents/list.html

@@ -76,15 +76,18 @@
             </div>
         </div>
     </section>
-
-    <!-- 章节列表将通过JavaScript动态生成 -->
-    <table id="list" lay-filter="list" class="table-header"></table>
-    <!--操作-->
-    <script type="text/html" id="listBar">
-        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
-        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="usable">已启用</a>
-        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
-    </script>
+    <div class="chapters-table" id="chaptersTable">
+        <div id="chaptersTableBody">
+            <!-- 章节列表将通过JavaScript动态生成 -->
+            <table id="list" lay-filter="list" class="table-header"></table>
+            <!--操作-->
+            <script type="text/html" id="listBar">
+                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
+                <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="usable">已启用</a>
+                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
+            </script>
+        </div>
+    </div>
 </div>
 
 <script src="../../../../static/assets/lib/jquery/jquery.js" th:src="@{/assets/lib/jquery/jquery.js}"></script>