Skip to content

Commit

Permalink
实现了真分页;重构和删除了部分方法
Browse files Browse the repository at this point in the history
  • Loading branch information
jiashuaizhang committed Dec 14, 2021
1 parent 7af369c commit 981f4b1
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 267 deletions.
7 changes: 6 additions & 1 deletion yyets-history/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.zhangjiashuai</groupId>
<artifactId>yyets-history</artifactId>
<version>1.1</version>
<version>2.0</version>
<name>yyets-history</name>
<description>a yyets history snapshot</description>
<properties>
Expand Down Expand Up @@ -63,6 +63,11 @@
<artifactId>xz</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.net.URLDecoder;
import cn.hutool.extra.compress.extractor.SevenZExtractor;
import com.zhangjiashuai.yyetshistory.repository.ResourceRepository;
import com.zhangjiashuai.yyetshistory.repository.impl.ResourceRepositoryJdbcImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.io.File;
Expand All @@ -25,12 +21,6 @@
@Configuration
public class AppConfig {

@Bean
@ConditionalOnMissingClass("org.apache.ibatis.annotations.Mapper")
public ResourceRepository resourceRepository(JdbcTemplate jdbcTemplate) {
return new ResourceRepositoryJdbcImpl(jdbcTemplate);
}

@Bean
@ConfigurationProperties(prefix = "yyets-history")
public YyetsHistoryProperties yyetsHistoryConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import java.util.LinkedHashSet;

import static com.zhangjiashuai.yyetshistory.repository.ResourceRepository.DEFAULT_PAGE_SIZE;

@Data
public class YyetsHistoryProperties {

private static final int DEFAULT_PAGE_SIZE = 10;
/**
* 保留的链接类型
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.zhangjiashuai.yyetshistory.controller;

import cn.hutool.db.PageResult;
import com.github.pagehelper.PageInfo;
import com.zhangjiashuai.yyetshistory.entity.Resource;
import com.zhangjiashuai.yyetshistory.service.ResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -20,10 +19,9 @@ public ResourceController(ResourceService resourceService) {

private ResourceService resourceService;

@GetMapping("/page/{pageNo}/{name}")
public PageResult<Resource> selectPage(@PathVariable("name") String name,
@PathVariable("pageNo") int pageNo) {
PageResult<Resource> resources = resourceService.selectPage(name, pageNo);
@GetMapping("/page")
public PageInfo<Resource> selectPage(String name, int pageNo) {
PageInfo<Resource> resources = resourceService.selectPage(name, pageNo);
log.info("查询成功, name: {}, pageNo: {}, pageSize: {}, total: {}",
name, pageNo, resources.getPageSize(), resources.getTotal());
return resources;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
package com.zhangjiashuai.yyetshistory.repository.impl;
package com.zhangjiashuai.yyetshistory.repository;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhangjiashuai.yyetshistory.entity.ResourceDO;
import com.zhangjiashuai.yyetshistory.repository.ResourceRepository;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface ResourceMapper extends BaseMapper<ResourceDO>, ResourceRepository {
public interface ResourceMapper extends BaseMapper<ResourceDO> {

static LambdaQueryWrapper<ResourceDO> queryWrapperByNameLike(String name) {
return Wrappers.<ResourceDO>lambdaQuery()
.like(ResourceDO::getName, name).orderByAsc(ResourceDO::getName);
}

default int countByNameLike(String name) {
return selectCount(queryWrapperByNameLike(name)).intValue();
default long countByNameLike(String name) {
return selectCount(queryWrapperByNameLike(name));
}

default List<ResourceDO> findByNameLike(String name) {
default List<ResourceDO> selectByNameLike(String name) {
return selectList(queryWrapperByNameLike(name));
}

default ResourceDO findById(long id) {
return selectById(id);
}

default ResourceDO findOneByName(String name) {
default ResourceDO selectOneByName(String name) {
List<ResourceDO> list = selectList(Wrappers.<ResourceDO>lambdaQuery()
.eq(ResourceDO::getName, name));
if(CollectionUtil.isEmpty(list)) {
Expand All @@ -39,7 +34,8 @@ default ResourceDO findOneByName(String name) {
return list.get(0);
}

default List<ResourceDO> findAll() {
default List<ResourceDO> selectAll() {
return selectList(Wrappers.emptyWrapper());
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
package com.zhangjiashuai.yyetshistory.service;

import cn.hutool.db.PageResult;
import com.github.pagehelper.PageInfo;
import com.zhangjiashuai.yyetshistory.entity.Resource;
import com.zhangjiashuai.yyetshistory.entity.ResourceDO;

import java.util.List;
import java.util.stream.Collectors;

public interface ResourceService {

ResourceDO findById(long id);

List<ResourceDO> findByNameLike(String name);

ResourceDO findOneByName(String name);

List<ResourceDO> findAll();
long countByNameLike(String name);

Resource parseResource(ResourceDO resourceDO);

Resource getResourceByName(String name);

Resource getResourceById(long id);

List<Resource> getResourceByNameLike(String name);

List<Resource> getAllResources();

PageResult<ResourceDO> selectDOPage(String name, int pageNo);
PageInfo<Resource> selectPage(String name, int pageNo, int pageSize);

default PageResult<Resource> selectPage(String name, int pageNo) {
PageResult<ResourceDO> doPageResult = selectDOPage(name, pageNo);
PageResult<Resource> pageResult = new PageResult<>(doPageResult.getPage(), doPageResult.getPageSize(), doPageResult.getTotal());
doPageResult.stream().map(this::parseResource).forEach(pageResult::add);
return pageResult;
}
PageInfo<Resource> selectPage(String name, int pageNo);

}
Loading

0 comments on commit 981f4b1

Please sign in to comment.