fix: 分页数据异常

This commit is contained in:
禾几海
2021-03-15 17:31:37 +08:00
parent 5632d47674
commit fafee4f918
5 changed files with 220 additions and 188 deletions

View File

@@ -1,6 +1,7 @@
package cn.celess.blog.mapper; package cn.celess.blog.mapper;
import cn.celess.blog.entity.ArticleTag; import cn.celess.blog.entity.ArticleTag;
import cn.celess.blog.entity.Tag;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@@ -27,6 +28,8 @@ public interface ArticleTagMapper {
List<ArticleTag> findAllByArticleId(Long articleId); List<ArticleTag> findAllByArticleId(Long articleId);
List<Tag> findTagByArticleId(Long articleId);
int deleteMultiById(List<ArticleTag> articleTags); int deleteMultiById(List<ArticleTag> articleTags);
List<ArticleTag> findArticleByTag(Long tagId); List<ArticleTag> findArticleByTag(Long tagId);

View File

@@ -64,6 +64,14 @@
and article_tag.t_id = tag_category.t_id and article_tag.t_id = tag_category.t_id
</select> </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 id="findOneById" resultMap="articleTagResultMap">
select * select *
from article_tag, from article_tag,

View File

@@ -19,8 +19,10 @@
<association property="category" column="a_category_id" javaType="cn.celess.blog.entity.TagCategory" <association property="category" column="a_category_id" javaType="cn.celess.blog.entity.TagCategory"
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap"> resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
</association> </association>
<collection property="tags" ofType="cn.celess.blog.entity.TagCategory" <collection property="tags" ofType="cn.celess.blog.entity.Tag"
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap"> select="cn.celess.blog.mapper.ArticleTagMapper.findTagByArticleId" column="a_id">
<id column="tagId" property="id"/>
<result column="tagName" property="name"/>
</collection> </collection>
</resultMap> </resultMap>
@@ -118,12 +120,12 @@
order by articleId desc order by articleId desc
</select> </select>
<select id="findAllByOpen" resultMap="articleViewResultMap"> <select id="findAllByOpen" resultMap="articleResultMap">
select * select *
from articleView from article
where isOpen = #{isOpen} where a_is_open = #{isOpen}
and isDelete = false and is_delete = false
order by articleId desc order by a_id desc
</select> </select>

View File

@@ -134,4 +134,13 @@ public class ArticleTagMapperTest extends BaseTest {
return articleTag; 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());
}
} }

View File

@@ -3,6 +3,7 @@ package cn.celess.blog.service;
import cn.celess.blog.BaseTest; import cn.celess.blog.BaseTest;
import cn.celess.blog.entity.model.ArticleModel; import cn.celess.blog.entity.model.ArticleModel;
import cn.celess.blog.entity.model.PageData; import cn.celess.blog.entity.model.PageData;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; 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::isDeleted));
assertTrue(pageData.getList().stream().anyMatch(articleModel -> !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);
}
} }