首页>代码>基于SSM的技术博客系统>/Art_Blog/src/main/java/com/java214/controller/BlogController.java
package com.java214.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java214.annotation.AccessLimit;
import com.java214.annotation.SystemLog;
import com.java214.model.Blog;
import com.java214.service.BlogService;
import com.java214.util.BlogIdSafeUtil;
import com.java214.util.ConstantUtil;



@Controller
public class BlogController {
	@Resource(name = "blogServiceImpl")
	private BlogService blogService;
	
	
	 @RequestMapping(value = "/find/{id}.html")
	 @SystemLog(description = ConstantUtil.BLOG_SELECT,userType=ConstantUtil.USERTYPE_USER) 
	 public String selectBlogById(@PathVariable Integer id,Model model) throws Exception {
		 int sId=BlogIdSafeUtil.BlogIdToSafe(id);
		 if(id==null||id<=0){
			//0表示查询 错误
			model.addAttribute("status", 0);
		}else{
			Blog blog=blogService.selectBlogUserById(sId);
			if(blog==null){
				//查询的博客不存在
				model.addAttribute("status", 500);
			}else{
				model.addAttribute("status", 200);
			}
			model.addAttribute("blog", blog);
		}
	        return "page/info";
	    }
	 
	 /**
	  * 查询后一篇博客信息
	  * @param id
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping(value = "/selectNextBlog")
	 @ResponseBody
	 public Map<String, Object> selectNextBlog(Integer id) throws Exception{
		 Map<String, Object> map=new HashMap<String, Object>();
		 Blog blog=blogService.selectNextBlog(id);
		 if(blog!=null){
			 map.put("status", 200);
		 }else{
			 //500表示:返回值为Null
			 map.put("status", 500);
		 }
		 map.put("blog", blog);
		 return map;
	 }
	 
	 /**
	  * 查询前一篇博客信息
	  * @param id
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping(value = "/selectPrevBlog")
	 @ResponseBody
	 public Map<String, Object> selectPrevBlog(Integer id) throws Exception{
		 Map<String, Object> map=new HashMap<String, Object>();
		 Blog blog=blogService.selectPrevBlog(id);
		 if(blog!=null){
			 map.put("status", 200);
		 }else{
			 //500表示:返回值为Null
			 map.put("status", 500);
		 }
		 map.put("blog", blog);
		 return map;
	 }
	 
	 /**
	  * 模糊组合分页查询博客信息(含content)
	  * @param id
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping(value = "/selectLikeBlogListByPage")
	 @ResponseBody
	 @AccessLimit(seconds=1,maxCount=15)
	 @SystemLog(description = ConstantUtil.BLOG_FINDKEY,userType=ConstantUtil.USERTYPE_USER) 
	 public Map<String, Object> selectLikeBlogListByPage(String param,Blog blog,@RequestParam(value="sort", required=true,defaultValue="addTime") String sort,@RequestParam(value="page", required=true,defaultValue="1") Integer page,@RequestParam(value="pageSize", required=true,defaultValue="10") Integer pageSize) throws Exception{
		 Map<String, Object> map=new HashMap<String, Object>();
		 map.put("sort", sort);
		 if(blog.getTitle()!=null&&blog.getTitle()!=""){
			 map.put("title", blog.getTitle());
		 }
		 if(blog.getIntroduction()!=null&&blog.getIntroduction()!=""){
			 map.put("introduction", blog.getIntroduction());
		 }
		 if(blog.getKeyword()!=null&&blog.getKeyword()!=""){
			 map.put("keyword", blog.getKeyword());
		 }
		 if(blog.getContent()!=null&&blog.getContent()!=""){
			 map.put("content", blog.getContent());
		 }
		 if(blog.getIstop()!=null){
			 map.put("isTop", blog.getIstop());
		 }
		 if(blog.getType()!=null){
			 map.put("type_id", blog.getType().getId());
		 }
		 map.put("status", 1);
		 if(blog.getStatus()!=null){
			 map.put("status", blog.getStatus());
		 }
		 if(blog.getIsrecommend()!=null){
			 map.put("isRecommend", blog.getIsrecommend());
		 }
		 if(blog.getAddtime()!=null){
			 map.put("addTime", blog.getAddtime());
		 }
		 //分页显示:第1页开始,每页显示10条记录
		 PageHelper.startPage(page, pageSize);
		 List<Blog> blogList=blogService.selectLikeBlogListByPageWithBlobs(map);
		 PageInfo<Blog> pageInfo=new PageInfo<Blog>(blogList);
		 Map<String, Object> returnMap=new HashMap<String, Object>();
		 if(blogList.size()>0){
			 returnMap.put("status", 200);
		 }else{
			 //500表示:返回值为Null
			 returnMap.put("status", 500);
		 }
		 returnMap.put("blogList", blogList);
		 returnMap.put("pageInfo", pageInfo);
		 return returnMap;
	 }
	
	 /**
	  * 模糊组合分页查询博客信息(and)
	  * @param id
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping(value = "/selectGroupLikeBlogListByPage")
	 @ResponseBody
	 @AccessLimit(seconds=1,maxCount=15)
	 public Map<String, Object> selectGroupLikeBlogListByPage(Blog blog,@RequestParam(value="sort", required=true,defaultValue="addTime") String sort,@RequestParam(value="page", required=true,defaultValue="1") Integer page,@RequestParam(value="pageSize", required=true,defaultValue="10") Integer pageSize) throws Exception{
		 Map<String, Object> map=new HashMap<String, Object>();
		 map.put("sort", sort);
		 if(blog.getTitle()!=null&&blog.getTitle()!=""){
			 map.put("title", blog.getTitle());
		 }
		 if(blog.getIntroduction()!=null&&blog.getIntroduction()!=""){
			 map.put("introduction", blog.getIntroduction());
		 }
		 if(blog.getKeyword()!=null&&blog.getKeyword()!=""){
			 map.put("keyword", blog.getKeyword());
		 }
		 if(blog.getContent()!=null&&blog.getContent()!=""){
			 map.put("content", blog.getContent());
		 }
		 if(blog.getIstop()!=null){
			 map.put("isTop", blog.getIstop());
		 }
		 if(blog.getType()!=null){
			 map.put("type_id", blog.getType().getId());
		 }
		 map.put("status", 1);
		 if(blog.getStatus()!=null){
			 map.put("status", blog.getStatus());
		 }
		 if(blog.getIsrecommend()!=null){
			 map.put("isRecommend", blog.getIsrecommend());
		 }
		 if(blog.getAddtime()!=null){
			 map.put("addTime", blog.getAddtime());
		 }
		 //分页显示:第1页开始,每页显示10条记录
		 PageHelper.startPage(page, pageSize);
		 List<Blog> blogList=blogService.selectGroupLikeBlogListByPage(map);
		 PageInfo<Blog> pageInfo=new PageInfo<Blog>(blogList);
		 Map<String, Object> returnMap=new HashMap<String, Object>();
		 if(blogList.size()>0){
			 returnMap.put("status", 200);
		 }else{
			 //500表示:返回值为Null
			 returnMap.put("status", 500);
		 }
		 returnMap.put("blogList", blogList);
		 returnMap.put("pageInfo", pageInfo);
		 return returnMap;
	 }

	 
	 
	 /**
      * 模糊组合分页查询博客信息(and)
      * @param id
      * @return
      * @throws Exception
      */
     @RequestMapping(value = "/selectBlogByAllType")
     @ResponseBody
     public Map<String, Object> selectBlogByAllType() throws Exception{
         Map<String,List<Blog>> blogMap=blogService.selectBlogByAllType();
         Map<String, Object> returnMap=new HashMap<String, Object>();
         if(blogMap.size()>0){
             returnMap.put("status", 200);
         }else{
             //500表示:返回值为Null
             returnMap.put("status", 500);
         }
         returnMap.put("blogMap", blogMap);
         return returnMap;
     }
}
最近下载更多
TY0165  LV20 2024年6月21日
lpwgzy  LV5 2023年10月9日
全栈小白  LV35 2023年9月11日
yunYUN123  LV1 2023年5月18日
tyyeng  LV18 2022年12月27日
利民提提  LV3 2022年11月20日
lilong007  LV23 2022年10月21日
cyx123456  LV6 2022年8月13日
getset  LV8 2022年6月26日
zhangjilu  LV18 2022年6月11日
最近浏览更多
xiaoaitx  LV8 1月2日
萌了个乖乖  LV12 2024年12月26日
三秋桂子  LV1 2024年12月22日
ma406805131  LV19 2024年12月18日
krispeng  LV14 2024年11月20日
897258976  LV8 2024年8月29日
TY0165  LV20 2024年6月21日
mc152921 2024年5月29日
暂无贡献等级
yellow_flowers  LV8 2024年4月26日
yqyqyqyqy  LV4 2024年4月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友