MISBoot快速开发平台

Controller控制层

一、 概述

1.作用

是Model与View之间沟通的桥梁,可以分派用户的请求并选择恰当的视图以用于显示,同时可以解释用户的输入并映射为模型层可执行的操作

请求顺序如下:

xxxx.html ——> controller ——> service ——>serviceImpl ——> mapper ——>mapper.xml

mapper.xml ——> mapper ——> serviceImpl ——> service ——> controller ——> xxxx.html

2.位置

包名:cn.ewsd.xxxx.Zzzz

3.命名方式

命名方式:XxxxController

4.继承

cn.ewsd.common.controller.BaseController

5.公用方法
序号方法名参数方法描述
1userInfo.getUserNameId()
获取当前用户ID
2userInfo.getUserName()
获取当前用户名称
3userInfo.getOrgId()
获取当前用户组织机构ID
4userInfo.getUuid()
获取当前用户的UUID
5userInfo.getRoleId()
获取当前用户角色ID
6getSaveData(Object)Object此方法可直接赋值:UUID,创建时间,创建人ID,创建人名称。使用方法如:getSaveData(sysUserBase);使用情况:在需要给对象赋值UUID,创建时间,创建人ID,创建人名称的情况下使用
7getUpdateData(Object)Object此方法可直接赋值:修改时间,修改人ID,修改人名称。使用方法如:getUpdateData(sysUserBase);使用情况:在需要给对象赋值修改时间,修改人ID,修改人名称的情况下使用
8success(“保存成功!”)message返回成功状态码及提示信息statusCode默认是200message根据传递参数如: success(“保存成功!”)参数{statusCode:”300”, message:”保存成功!”}
9failure(“保存失败!”)message返回失败状态码及提示信息statusCode默认是300message根据传递参数如: success(“保存失败!”)参数{statusCode:”200”,message:”保存失败!” }

二、示例代码

分页页面
//分页页面
    @RequestMapping("/index")
    @ControllerLog(description = "打开SysUser模块管理页面")
    public String index(@RequestParam Mapparams) {
        return "office/sysUser/index";
    }
新增页面
//新增页面
    @RequestMapping("/add")
    @ControllerLog(description = "打开SysUser模块新增页面")
    public String add() {
        return "office/sysUser/edit";
    }
编辑页面
//编辑页面
    @RequestMapping("/edit")
    @ControllerLog(description = "打开SysUser模块编辑页面")
    public String edit() {
        return "office/sysUser/edit";
    }
获取分页集
//获取分页集
    @ResponseBody
    @RequestMapping(value = "/getPageSet", method = RequestMethod.POST)
    @ControllerLog(description = "获得SysUser分页集数据")
    public Object getPageSet(PageParam pageParam) {
        String filterSort = "";   //传入sql的条件,可以自己添加
        filterSort = BaseUtils.filterSort(request, filterSort + getAuthFilter());
        PageSetpageSet = sysUserService.getPageSet(pageParam, filterSort);
        return pageSet;
    }
保存数据
//保存数据
    @ResponseBody
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ControllerLog(description = "保存SysUser模块数据")
    public Object save(@ModelAttribute SysUser sysUser) {
        int result = sysUserService.insertSelective(getSaveData(sysUser));  //getSaveData 直接赋值:UUID,创建时间,创建人ID,创建人名称。
        return result > 0 ? success("保存成功!") : failure("保存失败!");  //判断result是否保存成功,成功返回success,失败返回failure
    }
更新数据
//更新数据
    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ControllerLog(description = "更新SysUser模块数据")
    public Object update(@ModelAttribute SysUser sysUser) {
        int result = sysUserService.updateByPrimaryKeySelective(getUpdateData(sysUser)); //getSaveData 直接赋值:修改时间,修改人ID,修改人名称。
        return result > 0 ? success("更新成功!") : failure("更新失败!");               //判断result是否更新成功,成功返回success,失败返回failure
    }
获取详情
//获取详情
    @ResponseBody
    @RequestMapping(value = "/getDetailByUuid")
    @ControllerLog(description = "获得SysUser模块详细数据")
    public Object getDetailByUuid(String uuid) {
        SysUser sysUser = sysUserService.selectByPrimaryKey(uuid);  //根据uuid查询数据详情
        return sysUser;
    }
批量删除
//删除数据
    @ResponseBody
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    @ControllerLog(description = "删除SysUser模块数据")
    public Object deleteBatch(@RequestParam String[] uuid) {
        int result = sysUserService.executeDeleteBatch(uuid);                //根据数组UUID批量删除数据
        return result > 0 ? success("删除成功!") : failure("删除失败!");   //判断result是否删除成功,成功返回success,失败返回failure
    }
用户Controller
@Controller
    @RequestMapping("/sysUser")
    public class SysUserController extends OfficeBaseController {

        @Autowired
        private SysUserService sysUserService;

        //分页页面
        @RequestMapping("/index")
        @ControllerLog(description = "打开SysUser模块管理页面")
        public String index(@RequestParam Mapparams) {
            return "office/sysUser/index";
        }

        //获取分页集
        @ResponseBody
        @RequestMapping(value = "/getPageSet", method = RequestMethod.POST)
        @ControllerLog(description = "获得SysUser分页集数据")
        public Object getPageSet(PageParam pageParam) {
            String filterSort = "";
            filterSort = BaseUtils.filterSort(request, filterSort + getAuthFilter());
            PageSetpageSet = sysUserService.getPageSet(pageParam, filterSort);
            return pageSet;
        }

        //获取详情
        @ResponseBody
        @RequestMapping(value = "/getDetailByUuid")
        @ControllerLog(description = "获得SysUser模块详细数据")
        public Object getDetailByUuid(String uuid) {
            SysUser sysUser = sysUserService.selectByPrimaryKey(uuid);
            return sysUser;
        }

        //新增页面
        @RequestMapping("/add")
        @ControllerLog(description = "打开SysUser模块新增页面")
        public String add() {
            return "office/sysUser/edit";
        }

        //保存数据
        @ResponseBody
        @RequestMapping(value = "/save", method = RequestMethod.POST)
        @ControllerLog(description = "保存SysUser模块数据")
        public Object save(@ModelAttribute SysUser sysUser) {
            int result = sysUserService.insertSelective(getSaveData(sysUser));
            return result > 0 ? success("保存成功!") : failure("保存失败!");
        }

        //编辑页面
        @RequestMapping("/edit")
        @ControllerLog(description = "打开SysUser模块编辑页面")
        public String edit() {
            return "office/sysUser/edit";
        }

        //更新数据
        @ResponseBody
        @RequestMapping(value = "/update", method = RequestMethod.POST)
        @ControllerLog(description = "更新SysUser模块数据")
        public Object update(@ModelAttribute SysUser sysUser) {
            int result = sysUserService.updateByPrimaryKeySelective(getUpdateData(sysUser));
            return result > 0 ? success("更新成功!") : failure("更新失败!");
        }

        //删除数据
        @ResponseBody
        @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
        @ControllerLog(description = "删除SysUser模块数据")
        public Object deleteBatch(@RequestParam String[] uuid) {
            int result = sysUserService.executeDeleteBatch(uuid);
            return result > 0 ? success("删除成功!") : failure("删除失败!");
        }

    }
QQ在线咨询
客服 QQ
251122361
微信/手机
18973127736
办公电话
0731-89565588