首页>代码>ssm个人博客,包括登录注册,前端后台功能全面完整>/lingnanblog-/src/main/java/neusoft/controller/admin/BlogAdminController.java
package neusoft.controller.admin; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import neusoft.pojo.Blog; import neusoft.pojo.PageBean; import neusoft.service.BlogService; import neusoft.util.BlogIndex; import neusoft.util.ResponseUtil; import neusoft.util.StringUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import net.sf.json.JsonConfig; /** * 管理员博客Controller层 * @author Administrator * */ @Controller @RequestMapping("/admin/blog") public class BlogAdminController { @Autowired private BlogService blogService; // 博客索引 private BlogIndex blogIndex=new BlogIndex(); /** * 添加或者修改博客信息 * @param blog * @param response * @return * @throws Exception */ @RequestMapping("/save") public String save(Blog blog, HttpServletResponse response ,HttpSession session )throws Exception{ int resultTotal=0; // 操作的记录条数 if(blog.getId()==null){ resultTotal=blogService.add(blog); blogIndex.addIndex(blog); // 添加博客索引 }else{ resultTotal=blogService.update(blog); blogIndex.updateIndex(blog); // 更新博客索引 System.out.println(blog); } JSONObject result=new JSONObject(); if(resultTotal>0){ result.put("success", true); // session.setAttribute("blogMsg",blog); }else{ result.put("success", false); } ResponseUtil.write(response, result); return null; } /** * 分页查询博客信息 * @param page * @param rows * @param response * @return * @throws Exception */ @RequestMapping("/list") public String list(@RequestParam(value="page",required=false)String page,@RequestParam(value="rows",required=false)String rows,Blog s_blog,HttpServletResponse response)throws Exception{ System.out.println("jhdish"); PageBean pageBean=new PageBean(Integer.parseInt(page),Integer.parseInt(rows)); Map<String,Object> map=new HashMap<String,Object>(); map.put("title", StringUtil.formatLike(s_blog.getTitle())); map.put("start", pageBean.getStart()); map.put("size", pageBean.getPageSize()); List<Blog> blogList=blogService.list(map); Long total=blogService.getTotal(map); JSONObject result=new JSONObject(); JsonConfig jsonConfig=new JsonConfig(); jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor("yyyy-MM-dd")); JSONArray jsonArray=JSONArray.fromObject(blogList,jsonConfig); result.put("rows", jsonArray); result.put("total", total); ResponseUtil.write(response, result); System.out.println("eeeeeeeeeeeee"); return null; } /** * 删除博客信息 * @param ids * @param response * @return * @throws Exception */ @RequestMapping("/delete") public String delete(@RequestParam(value="ids")String ids,HttpServletResponse response)throws Exception{ String []idsStr=ids.split(","); for(int i=0;i<idsStr.length;i++){ blogService.delete(Integer.parseInt(idsStr[i])); blogIndex.deleteIndex(idsStr[i]); // 删除对应博客的索引 } JSONObject result=new JSONObject(); result.put("success", true); ResponseUtil.write(response, result); return null; } /** * 通过ID查找实体 * @param id * @param response * @return * @throws Exception */ @RequestMapping("/getById") public String getById(@RequestParam(value="id")String id,HttpServletResponse response)throws Exception{ Blog blog=blogService.getById(Integer.parseInt(id)); JSONObject jsonObject=JSONObject.fromObject(blog); ResponseUtil.write(response, jsonObject); return null; } }

问耳朵 LV2
2023年12月14日
我是helloworld LV23
2023年6月18日
monolog LV4
2023年6月18日
微信网友_6495054193971200 LV2
2023年5月30日
zxc131313 LV12
2022年12月9日
刘鹏yyds LV10
2022年11月23日
SCP11451 LV6
2022年10月10日
LJLljl002 LV5
2022年9月18日
℡ LV8
2022年6月6日
taoshen95 LV16
2022年5月6日

1140717565 LV2
7月18日
Yj123456k LV2
5月12日
xiaoaitx LV8
1月1日
ma406805131 LV19
2024年12月18日
dengge123 LV14
2024年12月13日
Wzzzccc
2024年10月21日
暂无贡献等级
我真的快死了
2024年10月13日
暂无贡献等级
TY0165 LV20
2024年6月24日
qiwwwww LV2
2024年6月19日
wanderingsoul LV2
2024年6月15日