添加分页插件支持

This commit is contained in:
柏码の讲师 2023-10-11 18:54:00 +08:00
parent f80c3ef0c7
commit 863f81a3b3
4 changed files with 23 additions and 5 deletions

View File

@ -0,0 +1,18 @@
package com.example.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisConfiguration {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//添加分页插件
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}

View File

@ -65,9 +65,9 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
//无缓存从数据库读取
Page<Topic> page = Page.of(pageNumber, 10);
if(type == 0)
this.baseMapper.selectPage(page, null);
this.baseMapper.selectPage(page, Wrappers.<Topic>query().orderByDesc("time"));
else
this.baseMapper.selectPage(page, Wrappers.<Topic>query().eq("type", type));
this.baseMapper.selectPage(page, Wrappers.<Topic>query().eq("type", type).orderByDesc("time"));
List<Topic> topics = page.getRecords();
if(topics.isEmpty()) return null;
list = topics.stream().map(this::resolveToPreview).toList();

View File

@ -18,13 +18,13 @@ public class CacheUtils {
public <T> T takeFromCache(String key, Class<T> dataType) {
String s = template.opsForValue().get(key);
if(s == null) return null;
return JSONObject.from(s).to(dataType);
return JSONObject.parseObject(s).to(dataType);
}
public <T> List<T> takeListFromCache(String key, Class<T> itemType) {
String s = template.opsForValue().get(key);
if(s == null) return null;
return JSONArray.from(s).toList(itemType);
return JSONArray.parseArray(s).toList(itemType);
}
public <T> void saveToCache(String key, T data, long expire) {

View File

@ -20,7 +20,7 @@ const today = computed(() => {
const date = new Date()
return `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`
})
get('/api/forum/list-topic?page=1&type=0', data => list.value = data)
get('/api/forum/list-topic?page=0&type=0', data => list.value = data)
navigator.geolocation.getCurrentPosition(position => {
const latitude = position.coords.latitude