fix: 分页数据异常
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cn.celess.blog.mapper;
|
||||
|
||||
import cn.celess.blog.entity.ArticleTag;
|
||||
import cn.celess.blog.entity.Tag;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -27,6 +28,8 @@ public interface ArticleTagMapper {
|
||||
|
||||
List<ArticleTag> findAllByArticleId(Long articleId);
|
||||
|
||||
List<Tag> findTagByArticleId(Long articleId);
|
||||
|
||||
int deleteMultiById(List<ArticleTag> articleTags);
|
||||
|
||||
List<ArticleTag> findArticleByTag(Long tagId);
|
||||
|
||||
@@ -64,6 +64,14 @@
|
||||
and article_tag.t_id = tag_category.t_id
|
||||
</select>
|
||||
|
||||
<select id="findTagByArticleId" resultMap="cn.celess.blog.mapper.TagMapper.tagResultMap">
|
||||
select tag_category.*
|
||||
from article_tag,
|
||||
tag_category
|
||||
where a_id = #{articleId}
|
||||
and article_tag.t_id = tag_category.t_id
|
||||
</select>
|
||||
|
||||
<select id="findOneById" resultMap="articleTagResultMap">
|
||||
select *
|
||||
from article_tag,
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
<association property="category" column="a_category_id" javaType="cn.celess.blog.entity.TagCategory"
|
||||
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||
</association>
|
||||
<collection property="tags" ofType="cn.celess.blog.entity.TagCategory"
|
||||
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||
<collection property="tags" ofType="cn.celess.blog.entity.Tag"
|
||||
select="cn.celess.blog.mapper.ArticleTagMapper.findTagByArticleId" column="a_id">
|
||||
<id column="tagId" property="id"/>
|
||||
<result column="tagName" property="name"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
@@ -118,12 +120,12 @@
|
||||
order by articleId desc
|
||||
</select>
|
||||
|
||||
<select id="findAllByOpen" resultMap="articleViewResultMap">
|
||||
<select id="findAllByOpen" resultMap="articleResultMap">
|
||||
select *
|
||||
from articleView
|
||||
where isOpen = #{isOpen}
|
||||
and isDelete = false
|
||||
order by articleId desc
|
||||
from article
|
||||
where a_is_open = #{isOpen}
|
||||
and is_delete = false
|
||||
order by a_id desc
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
@@ -134,4 +134,13 @@ public class ArticleTagMapperTest extends BaseTest {
|
||||
|
||||
return articleTag;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTagByArticleId() {
|
||||
Article article = articleMapper.findAll().get(0);
|
||||
assertNotNull(article);
|
||||
|
||||
List<Tag> tagByArticleId = articleTagMapper.findTagByArticleId(article.getId());
|
||||
assertNotEquals(0, tagByArticleId.size());
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package cn.celess.blog.service;
|
||||
import cn.celess.blog.BaseTest;
|
||||
import cn.celess.blog.entity.model.ArticleModel;
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -24,4 +25,13 @@ public class ArticleServiceTest extends BaseTest {
|
||||
assertTrue(pageData.getList().stream().anyMatch(ArticleModel::isDeleted));
|
||||
assertTrue(pageData.getList().stream().anyMatch(articleModel -> !articleModel.isDeleted()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrievePageForOpen() {
|
||||
PageData<ArticleModel> articleModelPageData = articleService.retrievePageForOpen(10, 1);
|
||||
assertEquals(10, articleModelPageData.getPageSize());
|
||||
assertEquals(1, articleModelPageData.getPageNum());
|
||||
assertEquals(10, articleModelPageData.getList().size());
|
||||
articleModelPageData.getList().forEach(Assert::assertNotNull);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user