首页>代码>基于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
2024年6月19日
yyhrhv LV8
2024年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日
最近浏览更多
奋斗的小蚂蚁 LV16
10月28日
chengguo123
4月2日
暂无贡献等级
三秋桂子 LV1
2024年12月22日
ma406805131 LV19
2024年12月18日
微信网友_7051335135711232
2024年6月24日
暂无贡献等级
lun123456
2024年6月22日
暂无贡献等级
yinfei305 LV2
2024年6月19日
木XX木大xqvq LV1
2024年6月2日
yyhrhv LV8
2024年5月23日
李俊雄 LV3
2024年5月8日

