首页>代码>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; } }
最近下载更多
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日
Jhhhhh LV6
2022年12月3日
孙龙52 LV6
2022年6月23日
1623096142 LV6
2022年5月20日
bunsWei LV2
2022年1月17日
最近浏览更多
860421 LV3
4月18日
skook7 LV2
2023年12月14日
fff2003 LV6
2023年11月17日
wnnmmb LV2
2023年11月12日
lingtiejing LV15
2023年10月1日
cheung524071 LV8
2023年8月23日
飞呀飞呀飞不放 LV7
2023年8月9日
2017143155 LV12
2023年8月3日
zhy1989wz LV6
2023年7月6日
dapeng0011 LV13
2023年6月19日