parent
639d1c6bc7
commit
7a20fdd63d
|
@ -2,16 +2,22 @@ package com.len.controller;
|
|||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.len.entity.ArticleCategory;
|
||||
import com.len.entity.ArticleList;
|
||||
import com.len.entity.BlogArticle;
|
||||
import com.len.entity.BlogCategory;
|
||||
import com.len.service.ArticleCategoryService;
|
||||
import com.len.service.BlogArticleService;
|
||||
import com.len.service.BlogCategoryService;
|
||||
import com.len.util.JsonUtil;
|
||||
import com.len.util.ReType;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -31,6 +37,12 @@ public class ArticleController {
|
|||
@Autowired
|
||||
private BlogArticleService articleService;
|
||||
|
||||
@Autowired
|
||||
private ArticleCategoryService articleCategoryService;
|
||||
|
||||
@Autowired
|
||||
private BlogCategoryService categoryService;
|
||||
|
||||
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@GetMapping("/articleList")
|
||||
|
@ -50,10 +62,11 @@ public class ArticleController {
|
|||
}
|
||||
|
||||
@GetMapping("/article/list")
|
||||
public ReType getList(BlogArticle article, Integer page, Integer limit) {
|
||||
public ReType getList(String code, Integer page, Integer limit) {
|
||||
limit = limit > 100 ? 100 : limit;
|
||||
Page<Object> startPage = PageHelper.startPage(page, limit);
|
||||
List<BlogArticle> articles = articleService.selectListByPage(article);
|
||||
|
||||
List<BlogArticle> articles = articleService.selectArticle(code);
|
||||
|
||||
List<ArticleList> articleLists = new ArrayList<>();
|
||||
articles.forEach(s -> articleLists.add(
|
||||
|
@ -62,6 +75,7 @@ public class ArticleController {
|
|||
format.format(s.getCreateDate()), s.getContent())
|
||||
)
|
||||
);
|
||||
long total = startPage.getTotal();
|
||||
return new ReType(startPage.getTotal(), startPage.getPageNum(), articleLists);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ public class BlogAdminController {
|
|||
|
||||
@GetMapping("/article/getList")
|
||||
public ReType getArticleList(BlogArticle article, Integer page, Integer limit) {
|
||||
Principal principal = LenUser.getPrincipal();
|
||||
return articleService.getList(article, page, limit);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,11 @@ package com.len.mapper;
|
|||
|
||||
import com.len.base.BaseMapper;
|
||||
import com.len.entity.BlogArticle;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BlogArticleMapper extends BaseMapper<BlogArticle, String> {
|
||||
|
||||
List<BlogArticle> selectArticle(@Param("code") String code);
|
||||
}
|
|
@ -4,6 +4,8 @@ import com.len.base.BaseService;
|
|||
import com.len.entity.BlogArticle;
|
||||
import com.len.util.JsonUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhuxiaomeng
|
||||
* @date 2018/9/9.
|
||||
|
@ -12,4 +14,6 @@ import com.len.util.JsonUtil;
|
|||
public interface BlogArticleService extends BaseService<BlogArticle, String> {
|
||||
|
||||
public JsonUtil getDetail(String code);
|
||||
|
||||
List<BlogArticle> selectArticle(String code);
|
||||
}
|
||||
|
|
|
@ -78,4 +78,9 @@ public class BlogArticleServiceImpl extends BaseServiceImpl<BlogArticle, String>
|
|||
json.setFlag(true);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlogArticle> selectArticle(String code) {
|
||||
return blogArticleMapper.selectArticle(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,4 +28,25 @@
|
|||
</where>
|
||||
order by read_number asc,create_date desc
|
||||
</select>
|
||||
|
||||
<select id="selectArticle" resultMap="BaseResultMap">
|
||||
select ba.id,ba.code,ba.title,ba.read_number,ba.top_num,ba.create_by,ba.create_date,
|
||||
left(ba.content,50) content
|
||||
from
|
||||
blog_article ba
|
||||
left JOIN
|
||||
blog_article_category bac
|
||||
on
|
||||
ba.id=bac.article_id
|
||||
LEFT JOIN
|
||||
blog_category bc
|
||||
on
|
||||
bac.category_id=bc.id
|
||||
<where>
|
||||
<if test="code!=null and code!=''">
|
||||
bc.code=#{code}
|
||||
</if>
|
||||
</where>
|
||||
order by ba.top_num desc,ba.create_date desc
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue