首页>代码>spring boot+mybatis+mysql基础配置实现部门数据增加查询更新功能>/springboot-demo/src/main/java/com/controller/DeptController.java
package com.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.service.DeptService;

/**
 * @PackageName: com.controller
 * @Description:
 * @Version: 1.0.0
 */
//相当于Controller  RestController该类中所有方法默认返回JSON
@RestController
@RequestMapping("dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 部门列表
     *
     * @return
     */
    @RequestMapping("list.do")//URL映射
    public Object hello() {
        List<Dept> list = deptService.getList(null);
        return list;
    }

    /**
     * 部门添加
     *
     * @param dept
     * @return
     */
    @RequestMapping("add.do")
    public Object add(@RequestBody Dept dept) {
        Map map = new HashMap();
        try {
            deptService.addDept(dept);
            map.put("returnInfo", "suc");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("returnInfo", "fail");
        }

        return map;
    }

    /**
     * 查询指定部门
     *
     * @param map
     * @return
     */
    @RequestMapping("select.do")
    public Object select(@RequestParam Map<String, Object> map) {
        return deptService.getList(map).get(0);
    }

    /**
     * 部门修改
     *
     * @param dept
     * @return
     */
    @RequestMapping("update.do")
    public Object update(@RequestBody Dept dept) {
        Map map = new HashMap();
        try {
            deptService.updateDept(dept);
            map.put("returnInfo", "suc");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("returnInfo", "fail");
        }
        return map;
    }

    /**
     * 部门删除
     *
     * @param map
     * @return
     */
    @RequestMapping("del.do")
    public Object del(@RequestParam Map<String, Object> map) {
        System.out.println(map);
        try {
            deptService.delDept(map);
            map.put("returnInfo", "suc");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("returnInfo", "fail");
        }
        return map;
    }
}
最近下载更多
yy1124218793  LV9 2月8日
wj3679  LV13 1月16日
a1677596408  LV23 1月13日
云着殇  LV9 2024年6月5日
skook7  LV2 2023年12月14日
cheung524071  LV8 2023年8月23日
2017143155  LV12 2023年8月3日
luoyongbing  LV8 2023年4月25日
starmomom  LV10 2023年3月14日
18120344519  LV4 2023年3月7日
最近浏览更多
哪里的完整版  LV8 2月27日
yy1124218793  LV9 2月8日
a1677596408  LV23 1月13日
TY0165  LV20 2024年6月24日
17380184110 2024年6月20日
暂无贡献等级
不正经的90后程序猿  LV1 2024年6月1日
1941549176  LV4 2024年4月29日
860421  LV3 2024年4月18日
skook7  LV2 2023年12月14日
fff2003  LV9 2023年11月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友