diff --git a/my-project-backend/src/main/java/com/example/config/MybatisConfiguration.java b/my-project-backend/src/main/java/com/example/config/MybatisConfiguration.java new file mode 100644 index 0000000..e9c758e --- /dev/null +++ b/my-project-backend/src/main/java/com/example/config/MybatisConfiguration.java @@ -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; + } +} diff --git a/my-project-backend/src/main/java/com/example/service/impl/TopicServiceImpl.java b/my-project-backend/src/main/java/com/example/service/impl/TopicServiceImpl.java index c35f1ca..98b1f16 100644 --- a/my-project-backend/src/main/java/com/example/service/impl/TopicServiceImpl.java +++ b/my-project-backend/src/main/java/com/example/service/impl/TopicServiceImpl.java @@ -65,9 +65,9 @@ public class TopicServiceImpl extends ServiceImpl implements //无缓存从数据库读取 Page page = Page.of(pageNumber, 10); if(type == 0) - this.baseMapper.selectPage(page, null); + this.baseMapper.selectPage(page, Wrappers.query().orderByDesc("time")); else - this.baseMapper.selectPage(page, Wrappers.query().eq("type", type)); + this.baseMapper.selectPage(page, Wrappers.query().eq("type", type).orderByDesc("time")); List topics = page.getRecords(); if(topics.isEmpty()) return null; list = topics.stream().map(this::resolveToPreview).toList(); diff --git a/my-project-backend/src/main/java/com/example/utils/CacheUtils.java b/my-project-backend/src/main/java/com/example/utils/CacheUtils.java index 7e3f2e7..eb9bda3 100644 --- a/my-project-backend/src/main/java/com/example/utils/CacheUtils.java +++ b/my-project-backend/src/main/java/com/example/utils/CacheUtils.java @@ -18,13 +18,13 @@ public class CacheUtils { public T takeFromCache(String key, Class 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 List takeListFromCache(String key, Class 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 void saveToCache(String key, T data, long expire) { diff --git a/my-project-frontend/src/views/forum/TopicList.vue b/my-project-frontend/src/views/forum/TopicList.vue index 0a825d5..12bd121 100644 --- a/my-project-frontend/src/views/forum/TopicList.vue +++ b/my-project-frontend/src/views/forum/TopicList.vue @@ -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