Commit 81fadc09 by liuyongshuai Committed by liuyongshuai

提交角色的controller

parent 7ea8cfca
package com.xzxtshiro.controller.admin;
import com.xzxtshiro.pojo.BaseModel;
import com.xzxtshiro.pojo.SysRole;
import com.xzxtshiro.service.SysPermissionNewService;
import com.xzxtshiro.service.SysRoleService;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* @author liuys
* @desc
* @date 2018-06-27 10:31
*/
@Controller
@RequestMapping(value = "/admin/role")
public class SysRoleController {
@Autowired
private SysRoleService sysRoleService;
@Autowired
private SysPermissionNewService sysPermissionService;
/**
* 跳转到角色列表
*
* @return
*/
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index(String msg, Model model) {
/*if (msg != null && msg != "") {
model.addAttribute("msg", "角色添加成功!");
}*/
return "admin/role/list";
}
/**
* 根据条件获取角色列表
*
* @param
* @return
*/
@ResponseBody
@RequestMapping(value = "/list", method = RequestMethod.GET)
public BaseModel list(SysRole role) {
return sysRoleService.selectSysRolePage(role);
}
/**
* 跳转到角色添加页面
*
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String addIndex(Model model) {
/**所有的权限*/
JSONArray json =sysPermissionService.selectAllPermissions();
model.addAttribute("permission",json);
/**获取所有的角色*/
JSONArray rolejson = sysRoleService.selectSysRolesByCondition(null);
model.addAttribute("role",rolejson);
return "admin/role/add";
}
/**
* 添加角色---提交
*
* @param
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(SysRole role, Model model) {
System.out.println("type.................................="+role.getType());
SysRole add = sysRoleService.add(role);
return "redirect:/admin/role/index?msg=success";
}
/**
* 跳转到角色修改页面
*
* @param
* @param model
* @return
*/
@RequestMapping(value = "/update/{roleId}", method = RequestMethod.GET)
public String updateIndex(@PathVariable("roleId") String roleId, Model model) {
Map<String,Object> roleMap = sysRoleService.selectSysRoleById(roleId);
/**所有的权限*/
JSONArray json =sysPermissionService.selectAllPermissions();
/**获取所有的角色*/
JSONArray rolejson = sysRoleService.selectSysRolesByCondition(null);
model.addAttribute("AllPermission",json);
model.addAttribute("oldPermission",roleMap.get("oldPermission"));
model.addAttribute("AllRole",rolejson);
model.addAttribute("role", roleMap.get("role"));
return "admin/role/update";
}
/**
* 更新角色,删除授权并重新进行授权
* @param role
* @param model
* @return
*/
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(SysRole role, Model model) {
SysRole update = sysRoleService.update(role);
return "redirect:/admin/role/index?msg=success";
}
/**
* 删除角色,并删除授权
* @param sysRole
* @return
*/
@ResponseBody
@RequestMapping(value = "/deleteRoleById",method = RequestMethod.POST)
public String deleteRoleById(SysRole sysRole){
Integer i=sysRoleService.deleteSysRoleById(sysRole);
if (i==1) {
return "success";
}else {
return "error";
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment