提交 31410fd8 编写于 作者: S smileNicky

文章类别实现

上级 96deff96
......@@ -47,4 +47,12 @@ public interface ArticleRepository extends PagingAndSortingRepository<Article,In
*/
@Query("from Article a where a.articleId=:articleId")
public Article getArticleInfo(@Param("articleId")int articleId);
/**
* 根据类别id获取文章列表
* @param typeId
* @return
*/
@Query("from Article a where a.typeId=:typeId")
public List<Article> listArticleByTypeId(@Param("typeId")int typeId);
}
......@@ -118,4 +118,13 @@ public class ArticleService {
public Article getArticleInfo(int articleId) {
return articleRepository.getArticleInfo(articleId);
}
/**
* 根据类别id或者文章列表
* @param typeId
* @return
*/
public List<Article> listArticleByTypeId(int typeId) {
return articleRepository.listArticleByTypeId(typeId);
}
}
package net.myblog.web.controller;
import net.myblog.entity.Article;
import net.myblog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
* <pre>
* 文章类别控制类
* </pre>
*
* @author nicky
* <pre>
* 修改记录
* 修改后版本: 修改人: 修改日期: 2019年02月01日 修改内容:
* </pre>
*/
@Controller
@RequestMapping("/article/label")
public class LabelArticleController extends BaseController{
@Autowired ArticleService articleService;
@RequestMapping(value = "/toListLabelArticle",method = RequestMethod.GET)
public ModelAndView toListLabelArticle(@RequestParam("typeId")String typeId){
ModelAndView mv = this.getModelAndView();
List<Article> articles = this.articleService.listArticleByTypeId(Integer.parseInt(typeId));
mv.addObject("articles", articles);
mv.setViewName("myblog/article/article_label");
return mv;
}
}
......@@ -41,7 +41,7 @@ background:url("plugins/easyui-1.3.4/themes/icons/search.png") no-repeat scroll
<c:forEach items="${articles}" var="ar" varStatus="art">
<ul>
<h2>
<a title="${ar.articleName }" href="/" target="_blank">
<a title="${ar.articleName }" href="article/details.do?articleId=${ar.articleId}" target="_blank">
${ar.articleName }
</a></h2>
<p>${ar.articleContent }</p>
......
......@@ -74,7 +74,7 @@ document.write('<param name="FlashVars" value="bcastr_file='+files+'&bcastr_link
<c:choose>
<c:when test="${not empty articleSorts}">
<c:forEach items="${articleSorts }" var="a" varStatus="as">
<li><a href="#" target="_blank">${a.name }</a></li>
<li><a href="article/label/toListLabelArticle.do?typeId=${a.typeId}" target="_blank">${a.name }</a></li>
</c:forEach>
</c:when>
<c:otherwise>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册