首页>代码>基于Spring+Spring MVC+Mybatis开发ssm网站后台管理系统,MyBatis Generator支持简单代码生成>/ssm/src/main/java/com/xiaoshu/controller/OperationController.java
package com.xiaoshu.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; 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 com.xiaoshu.entity.Menu; import com.xiaoshu.entity.Operation; import com.xiaoshu.service.OperationService; import com.xiaoshu.util.StringUtil; import com.xiaoshu.util.WriterUtil; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageInfo; @Controller @RequestMapping("operation") public class OperationController { static Logger logger = Logger.getLogger(OperationController.class); @Autowired private OperationService operationService; @RequestMapping("operationIndex") public String index(HttpServletRequest request,HttpServletResponse response,@RequestParam("menuid") String menuid){ if(StringUtil.isNotEmpty(menuid)){ Menu menu = operationService.getMenuByMenuid(Integer.parseInt(menuid)); request.setAttribute("menuid",menuid); request.setAttribute("menuname",menu.getMenuname()); } return "operation"; } @RequestMapping("operationList") public void list(HttpServletRequest request,HttpServletResponse response,Integer menuid,Integer page,Integer rows){ try { Operation operation = new Operation(); operation.setMenuid(menuid); PageInfo<Operation> pageinfo = operationService.findOperationPage(operation,page,rows); JSONObject jsonObj = new JSONObject();//new一个JSON jsonObj.put("total",pageinfo.getPages()); jsonObj.put("records", pageinfo.getTotal()); jsonObj.put("rows", pageinfo.getList()); WriterUtil.write(response,jsonObj.toString()); } catch (Exception e) { e.printStackTrace(); logger.error("按钮展示错误",e); } } @RequestMapping("reserveOperation") public void reserveMenu(HttpServletRequest request,HttpServletResponse response,Operation operation){ Integer operationid = operation.getOperationid(); JSONObject result=new JSONObject(); try { if (operationid != null) { //更新操作 operation.setMenuid(operationid); operationService.updateOperation(operation); } else { operationService.addOperation(operation); } result.put("success", true); } catch (Exception e) { e.printStackTrace(); logger.error("按钮保存错误",e); result.put("success", true); result.put("errorMsg", "对不起,操作失败!"); } WriterUtil.write(response, result.toString()); } @RequestMapping("deleteOperation") public void delUser(HttpServletRequest request,HttpServletResponse response,Integer id){ JSONObject result=new JSONObject(); try { operationService.deleteOperation(id); result.put("success", true); } catch (Exception e) { e.printStackTrace(); logger.error("删除按钮错误",e); result.put("errorMsg", "对不起,删除失败"); } WriterUtil.write(response, result.toString()); } }
最近下载更多
yinfei305 LV2
6月19日
yyhrhv LV8
5月23日
逝水莲花 LV7
2023年12月1日
13188866605 LV12
2023年10月22日
38735466 LV11
2023年7月4日
小龙快飞 LV5
2022年12月29日
renyuan LV9
2022年12月7日
微信网友_6108289352863744 LV4
2022年9月16日
chenhan413 LV10
2022年5月30日
y1214435276 LV9
2022年5月6日