diff --git a/pom.xml b/pom.xml index 252b865..5cf9711 100644 --- a/pom.xml +++ b/pom.xml @@ -156,6 +156,7 @@ ${bitwalker.version} + com.alibaba.fastjson2 diff --git a/src/main/java/com/ruoyi/common/utils/ListPage.java b/src/main/java/com/ruoyi/common/utils/ListPage.java new file mode 100644 index 0000000..570ea37 --- /dev/null +++ b/src/main/java/com/ruoyi/common/utils/ListPage.java @@ -0,0 +1,34 @@ +package com.ruoyi.common.utils; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author wyd + */ +public class ListPage { + + + + /** + * 利用java8的stream对list进行分页 + * @param list 需要分页的list,一般为全量 + * @param pageNum 当前页 + * @param pageSize 每页大小 + * @param 元素 + * @return list + */ + public static List getLimitList(List list, Integer pageNum, Integer pageSize) { + if (list == null || list.size() <= 0) { + return list; + } + if (pageNum == null || pageNum < 1) { + pageNum = 1; + } + if (pageSize == null || pageSize < 0) { + pageSize = 10; + } + + return list.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); + } +} diff --git a/src/main/java/com/ruoyi/common/utils/QueryPage.java b/src/main/java/com/ruoyi/common/utils/QueryPage.java new file mode 100644 index 0000000..304ce94 --- /dev/null +++ b/src/main/java/com/ruoyi/common/utils/QueryPage.java @@ -0,0 +1,57 @@ +package com.ruoyi.common.utils; + +import com.alibaba.fastjson2.JSON; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * description + * + * @author lxp + * @version V1.0 + * @date 2021/12/22 14:23 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@ApiModel(value = "分页参数", description = "分页查询model") +public class QueryPage { + + private static final long serialVersionUID = 1L; + + /** + * 降序 + */ + public static final String DESC = "descend"; + /** + * 升序 + */ + public static final String ASC = "ascend"; + + @ApiModelProperty(value = "页号") + private Integer pageNum = 0; + + @ApiModelProperty(value = "页面大小") + private Integer pageSize = 10; + + @ApiModelProperty("过滤") + protected Map filter; + + @ApiModelProperty("排序") + protected Map sorter; + + @SuppressWarnings("unchecked") + public void setFilter(String filter) { + this.filter = JSON.parseObject(filter, Map.class); + } + + @SuppressWarnings("unchecked") + public void setSorter(String sorter) { + this.sorter = JSON.parseObject(sorter, Map.class); + } +} diff --git a/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java b/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java index 62d5c20..cdf29d0 100644 --- a/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java +++ b/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java @@ -22,6 +22,7 @@ public class MybatisPlusConfig public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 分页插件 interceptor.addInnerInterceptor(paginationInnerInterceptor()); // 乐观锁插件 diff --git a/src/main/java/com/ruoyi/framework/web/domain/R.java b/src/main/java/com/ruoyi/framework/web/domain/R.java index bd4f69f..ceb225f 100644 --- a/src/main/java/com/ruoyi/framework/web/domain/R.java +++ b/src/main/java/com/ruoyi/framework/web/domain/R.java @@ -1,6 +1,8 @@ package com.ruoyi.framework.web.domain; import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonInclude; import com.ruoyi.common.constant.HttpStatus; /** @@ -22,6 +24,15 @@ public class R implements Serializable private String msg; + @JsonInclude(JsonInclude.Include.NON_NULL) + private Integer pageNum; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private Integer total; + private T data; public static R ok() @@ -39,6 +50,12 @@ public class R implements Serializable return restResult(data, SUCCESS, msg); } + /*分页*/ + public static R page(Integer pageNum,Integer pageSize,Integer total,T data) + { + return restResultPage(SUCCESS,pageNum,pageSize,total,data, "操作成功"); + } + public static R fail() { return restResult(null, FAIL, "操作失败"); @@ -72,6 +89,17 @@ public class R implements Serializable apiResult.setMsg(msg); return apiResult; } + private static R restResultPage(int code,Integer pageNum,Integer pageSize,Integer total,T data,String msg) + { + R apiResult = new R<>(); + apiResult.setCode(code); + apiResult.setMsg(msg); + apiResult.setPageNum(pageNum); + apiResult.setPageSize(pageSize); + apiResult.setTotal(total); + apiResult.setData(data); + return apiResult; + } public int getCode() { @@ -112,4 +140,28 @@ public class R implements Serializable { return R.SUCCESS == ret.getCode(); } + public Integer getPageNum() { + return pageNum; + } + + public void setPageNum(Integer pageNum) { + this.pageNum = pageNum; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + } diff --git a/src/main/java/com/ruoyi/project/about/controller/AboutPartThreeController.java b/src/main/java/com/ruoyi/project/about/controller/AboutPartThreeController.java index 423581e..65be97c 100644 --- a/src/main/java/com/ruoyi/project/about/controller/AboutPartThreeController.java +++ b/src/main/java/com/ruoyi/project/about/controller/AboutPartThreeController.java @@ -1,6 +1,18 @@ package com.ruoyi.project.about.controller; import java.util.List; import javax.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.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.ruoyi.common.utils.ListPage; +import com.ruoyi.common.utils.PageUtils; +import com.ruoyi.common.utils.QueryPage; +import com.ruoyi.framework.web.controller.BaseController; +import com.ruoyi.framework.web.page.TableDataInfo; +import com.ruoyi.project.about.mapper.AboutPartThreeMapper; import lombok.extern.slf4j.Slf4j; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -24,7 +36,7 @@ import com.ruoyi.framework.web.domain.R; @Api(tags = "关于第三部分") @RestController @RequestMapping("/PartThree") -public class AboutPartThreeController { +public class AboutPartThreeController extends BaseController { @Resource private IAboutPartThreeService aboutPartThreeService; @@ -38,6 +50,17 @@ public class AboutPartThreeController { List list = aboutPartThreeService.list(); return R.ok(list); } + /** + * 关于第三部分分页列表 + */ + @PreAuthorize("@ss.hasPermi('PartThree:partthree:listpage')") + @ApiOperation(value = "关于第三部分分页列表", notes = "关于第三部分分页列表信息") + @GetMapping("/listPage") + public R listPage(QueryPage queryPage, AboutPartThree aboutPartThree) { + startPage(); + List list = aboutPartThreeService.selectAboutPartThreeList(aboutPartThree); + return R.page(queryPage.getPageNum(),queryPage.getPageSize(),list.size(),list); + } /** * 关于第三部分id详细信息 */ diff --git a/src/main/java/com/ruoyi/project/about/domain/AboutPartThree.java b/src/main/java/com/ruoyi/project/about/domain/AboutPartThree.java index aa40f89..a3ce119 100644 --- a/src/main/java/com/ruoyi/project/about/domain/AboutPartThree.java +++ b/src/main/java/com/ruoyi/project/about/domain/AboutPartThree.java @@ -57,12 +57,12 @@ private static final long serialVersionUID=1L; @TableField("sorts") private Long sorts; /** 创建时间 */ - @ApiModelProperty("创建时间") + @ApiModelProperty(value = "创建时间",hidden = true) @TableField("create_time") @JSONField(serializeUsing = ToStringSerializer.class) private String createTime; /** 更新时间 */ - @ApiModelProperty("更新时间") + @ApiModelProperty(value = "更新时间",hidden = true) @TableField("update_time") @JSONField(serializeUsing = ToStringSerializer.class) private String updateTime; diff --git a/src/main/java/com/ruoyi/project/about/mapper/AboutPartThreeMapper.java b/src/main/java/com/ruoyi/project/about/mapper/AboutPartThreeMapper.java index 24f7d63..350dd30 100644 --- a/src/main/java/com/ruoyi/project/about/mapper/AboutPartThreeMapper.java +++ b/src/main/java/com/ruoyi/project/about/mapper/AboutPartThreeMapper.java @@ -3,6 +3,9 @@ package com.ruoyi.project.about.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ruoyi.project.about.domain.AboutPartThree; + +import java.util.List; + /** * 关于第三部分Mapper接口 * @@ -10,5 +13,5 @@ import com.ruoyi.project.about.domain.AboutPartThree; * @date 2024-04-19 */ public interface AboutPartThreeMapper extends BaseMapper { - + public List selectAboutPartThreeList(AboutPartThree aboutPartThree); } diff --git a/src/main/java/com/ruoyi/project/about/service/IAboutPartThreeService.java b/src/main/java/com/ruoyi/project/about/service/IAboutPartThreeService.java index bed5663..797ef0f 100644 --- a/src/main/java/com/ruoyi/project/about/service/IAboutPartThreeService.java +++ b/src/main/java/com/ruoyi/project/about/service/IAboutPartThreeService.java @@ -4,6 +4,8 @@ package com.ruoyi.project.about.service; import com.ruoyi.project.about.domain.AboutPartThree; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; + /** * 关于第三部分Service接口 * @@ -11,5 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService; * @date 2024-04-19 */ public interface IAboutPartThreeService extends IService { - + public List selectAboutPartThreeList(AboutPartThree aboutPartThree); } diff --git a/src/main/java/com/ruoyi/project/about/service/impl/AboutPartThreeServiceImpl.java b/src/main/java/com/ruoyi/project/about/service/impl/AboutPartThreeServiceImpl.java index 85bb0f0..28d207f 100644 --- a/src/main/java/com/ruoyi/project/about/service/impl/AboutPartThreeServiceImpl.java +++ b/src/main/java/com/ruoyi/project/about/service/impl/AboutPartThreeServiceImpl.java @@ -4,7 +4,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.project.about.mapper.AboutPartThreeMapper; import com.ruoyi.project.about.domain.AboutPartThree; import com.ruoyi.project.about.service.IAboutPartThreeService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.List; + /** * 关于第三部分Service业务层处理 * @@ -13,5 +17,11 @@ import org.springframework.stereotype.Service; */ @Service public class AboutPartThreeServiceImpl extends ServiceImpl implements IAboutPartThreeService { + @Autowired + private AboutPartThreeMapper aboutPartThreeMapper; + @Override + public List selectAboutPartThreeList(AboutPartThree aboutPartThree) { + return aboutPartThreeMapper.selectAboutPartThreeList(aboutPartThree); + } } diff --git a/src/main/resources/mybatis/PartThree/AboutPartThreeMapper.xml b/src/main/resources/mybatis/PartThree/AboutPartThreeMapper.xml index 9756a1c..8535583 100644 --- a/src/main/resources/mybatis/PartThree/AboutPartThreeMapper.xml +++ b/src/main/resources/mybatis/PartThree/AboutPartThreeMapper.xml @@ -3,4 +3,26 @@ + + + + + + + + + + + + select id, title_one, title_two, remarks, icon, create_time, update_time from about_part_three + + \ No newline at end of file diff --git a/src/main/resources/vm/java/controller.java.vm b/src/main/resources/vm/java/controller.java.vm index 6c9d936..a10bbb2 100644 --- a/src/main/resources/vm/java/controller.java.vm +++ b/src/main/resources/vm/java/controller.java.vm @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.jg.framework.web.controller.BaseController; import ${packageName}.domain.${ClassName}; import ${packageName}.service.I${ClassName}Service; import com.ruoyi.framework.web.domain.R; @@ -27,10 +28,23 @@ import com.ruoyi.framework.web.domain.R; @Api(tags = "${functionName}") @RestController @RequestMapping("/${moduleName}") -public class ${ClassName}Controller { +public class ${ClassName}Controller extends BaseController{ @Resource private I${ClassName}Service ${className}Service; + + + /** + * ${functionName}分页列表 + */ + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:listPage')") + @ApiOperation(value = "${functionName}分页列表", notes = "${functionName}分页列表信息") + @PostMapping("/listPage") + public R listPage(QueryPage queryPage,${ClassName} ${className}) { + startPage(); + List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); + return R.page(queryPage.getPageNum(),queryPage.getPageSize(),list.size(),list); + } /** * ${functionName}列表 */ diff --git a/src/main/resources/vm/java/domain.java.vm b/src/main/resources/vm/java/domain.java.vm index 946dbb9..a594fd9 100644 --- a/src/main/resources/vm/java/domain.java.vm +++ b/src/main/resources/vm/java/domain.java.vm @@ -55,7 +55,7 @@ private static final long serialVersionUID=1L; #else #if($column.javaType == 'Date') /** $column.columnComment */ - @ApiModelProperty("$column.columnComment") + @ApiModelProperty(value = "$column.columnComment",hidden = true) @TableField("$column.columnName") @JSONField(serializeUsing = ToStringSerializer.class) private String $column.javaField; diff --git a/src/main/resources/vm/java/mapper.java.vm b/src/main/resources/vm/java/mapper.java.vm index e861409..4ecac61 100644 --- a/src/main/resources/vm/java/mapper.java.vm +++ b/src/main/resources/vm/java/mapper.java.vm @@ -10,5 +10,11 @@ import ${packageName}.domain.${ClassName}; * @date ${datetime} */ public interface ${ClassName}Mapper extends BaseMapper<${ClassName}> { - + /** + * 查询${functionName}列表 + * + * @param ${className} ${functionName} + * @return ${functionName}集合 + */ + public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); } diff --git a/src/main/resources/vm/java/service.java.vm b/src/main/resources/vm/java/service.java.vm index e06f8e4..3b40beb 100644 --- a/src/main/resources/vm/java/service.java.vm +++ b/src/main/resources/vm/java/service.java.vm @@ -11,5 +11,11 @@ import com.baomidou.mybatisplus.extension.service.IService; * @date ${datetime} */ public interface I${ClassName}Service extends IService<${ClassName}> { - + /** + * 查询${functionName}列表 + * + * @param ${className} ${functionName} + * @return ${functionName}集合 + */ + public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); } diff --git a/src/main/resources/vm/java/serviceImpl.java.vm b/src/main/resources/vm/java/serviceImpl.java.vm index e13a05b..8568b56 100644 --- a/src/main/resources/vm/java/serviceImpl.java.vm +++ b/src/main/resources/vm/java/serviceImpl.java.vm @@ -5,6 +5,9 @@ import ${packageName}.mapper.${ClassName}Mapper; import ${packageName}.domain.${ClassName}; import ${packageName}.service.I${ClassName}Service; import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + /** * ${functionName}Service业务层处理 * @@ -14,4 +17,18 @@ import org.springframework.stereotype.Service; @Service public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service { + @Resource + private ${ClassName}Mapper ${className}Mapper; + + /** + * 查询${functionName} + * + * @param ${pkColumn.javaField} ${functionName}主键 + * @return ${functionName} + */ + @Override + public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}) + { + return ${className}Mapper.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}); + } } diff --git a/src/main/resources/vm/xml/mapper.xml.vm b/src/main/resources/vm/xml/mapper.xml.vm index 4916767..d7b2468 100644 --- a/src/main/resources/vm/xml/mapper.xml.vm +++ b/src/main/resources/vm/xml/mapper.xml.vm @@ -2,5 +2,25 @@ + + #foreach ($column in $columns) + + #end + + #if($table.sub) + + + + + + #foreach ($column in $subTable.columns) + + #end + + #end + + + select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName} + \ No newline at end of file diff --git a/target/classes/com/ruoyi/framework/config/MybatisPlusConfig.class b/target/classes/com/ruoyi/framework/config/MybatisPlusConfig.class index 8c79958..f9aa923 100644 Binary files a/target/classes/com/ruoyi/framework/config/MybatisPlusConfig.class and b/target/classes/com/ruoyi/framework/config/MybatisPlusConfig.class differ diff --git a/target/classes/com/ruoyi/framework/web/domain/R.class b/target/classes/com/ruoyi/framework/web/domain/R.class index 72c1ab1..89a153a 100644 Binary files a/target/classes/com/ruoyi/framework/web/domain/R.class and b/target/classes/com/ruoyi/framework/web/domain/R.class differ diff --git a/target/classes/com/ruoyi/project/about/controller/AboutPartThreeController.class b/target/classes/com/ruoyi/project/about/controller/AboutPartThreeController.class index ff5092c..1d07c96 100644 Binary files a/target/classes/com/ruoyi/project/about/controller/AboutPartThreeController.class and b/target/classes/com/ruoyi/project/about/controller/AboutPartThreeController.class differ diff --git a/target/classes/com/ruoyi/project/about/domain/AboutPartThree.class b/target/classes/com/ruoyi/project/about/domain/AboutPartThree.class index 7f97d1b..5c6442a 100644 Binary files a/target/classes/com/ruoyi/project/about/domain/AboutPartThree.class and b/target/classes/com/ruoyi/project/about/domain/AboutPartThree.class differ diff --git a/target/classes/com/ruoyi/project/about/mapper/AboutPartThreeMapper.class b/target/classes/com/ruoyi/project/about/mapper/AboutPartThreeMapper.class index 4dcf750..4adb278 100644 Binary files a/target/classes/com/ruoyi/project/about/mapper/AboutPartThreeMapper.class and b/target/classes/com/ruoyi/project/about/mapper/AboutPartThreeMapper.class differ diff --git a/target/classes/com/ruoyi/project/about/service/IAboutPartThreeService.class b/target/classes/com/ruoyi/project/about/service/IAboutPartThreeService.class index 6f116d5..32f54da 100644 Binary files a/target/classes/com/ruoyi/project/about/service/IAboutPartThreeService.class and b/target/classes/com/ruoyi/project/about/service/IAboutPartThreeService.class differ diff --git a/target/classes/com/ruoyi/project/about/service/impl/AboutPartThreeServiceImpl.class b/target/classes/com/ruoyi/project/about/service/impl/AboutPartThreeServiceImpl.class index 9c66cbb..0c5541a 100644 Binary files a/target/classes/com/ruoyi/project/about/service/impl/AboutPartThreeServiceImpl.class and b/target/classes/com/ruoyi/project/about/service/impl/AboutPartThreeServiceImpl.class differ diff --git a/target/classes/mybatis/PartThree/AboutPartThreeMapper.xml b/target/classes/mybatis/PartThree/AboutPartThreeMapper.xml index 9756a1c..8535583 100644 --- a/target/classes/mybatis/PartThree/AboutPartThreeMapper.xml +++ b/target/classes/mybatis/PartThree/AboutPartThreeMapper.xml @@ -3,4 +3,26 @@ + + + + + + + + + + + + select id, title_one, title_two, remarks, icon, create_time, update_time from about_part_three + + \ No newline at end of file diff --git a/target/classes/vm/java/controller.java.vm b/target/classes/vm/java/controller.java.vm index 6c9d936..a10bbb2 100644 --- a/target/classes/vm/java/controller.java.vm +++ b/target/classes/vm/java/controller.java.vm @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.jg.framework.web.controller.BaseController; import ${packageName}.domain.${ClassName}; import ${packageName}.service.I${ClassName}Service; import com.ruoyi.framework.web.domain.R; @@ -27,10 +28,23 @@ import com.ruoyi.framework.web.domain.R; @Api(tags = "${functionName}") @RestController @RequestMapping("/${moduleName}") -public class ${ClassName}Controller { +public class ${ClassName}Controller extends BaseController{ @Resource private I${ClassName}Service ${className}Service; + + + /** + * ${functionName}分页列表 + */ + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:listPage')") + @ApiOperation(value = "${functionName}分页列表", notes = "${functionName}分页列表信息") + @PostMapping("/listPage") + public R listPage(QueryPage queryPage,${ClassName} ${className}) { + startPage(); + List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); + return R.page(queryPage.getPageNum(),queryPage.getPageSize(),list.size(),list); + } /** * ${functionName}列表 */ diff --git a/target/classes/vm/java/domain.java.vm b/target/classes/vm/java/domain.java.vm index 946dbb9..a594fd9 100644 --- a/target/classes/vm/java/domain.java.vm +++ b/target/classes/vm/java/domain.java.vm @@ -55,7 +55,7 @@ private static final long serialVersionUID=1L; #else #if($column.javaType == 'Date') /** $column.columnComment */ - @ApiModelProperty("$column.columnComment") + @ApiModelProperty(value = "$column.columnComment",hidden = true) @TableField("$column.columnName") @JSONField(serializeUsing = ToStringSerializer.class) private String $column.javaField;