发表于: 2020-07-18 23:48:24

1 1279


剩下的代码写完

@Controller
public class BannerController {
private static final Logger logger = LogManager.getLogger(BannerController.class);

   @Autowired
   private BannerService bannerService;

   @GetMapping("/Banner")//查询banner
   @ResponseBody
   public Map<String,Object> selectBanner(Banner banner){
logger.info("select banner is :" + banner);
       Map<String,Object> resultMap = new HashMap<>();
       try {
List<Banner> list = bannerService.selectBanner(banner);
           if(list.isEmpty()){
resultMap.put("code",404);
               resultMap.put("msg","");
           }else {
resultMap.put("code", 200);
               resultMap.put("msg", "查询成功");
               resultMap.put("data", list);
           }
}catch (Exception e){
resultMap.put("code",404);
           resultMap.put("msg","查询失败");
           e.printStackTrace();
           logger.error("select banner error");
       }
return resultMap;
   }

@ResponseBody
   @PostMapping("/Banner")//新增banner
   public Map<String,Object> insertBanner(Banner banner){
logger.info("add banner is :" + banner);
       Map<String,Object> resultMap = new HashMap<>();
       try {
Long time = System.currentTimeMillis();
           banner.setCreatby("管理员1");
           banner.setCreatat(time);
           banner.setUpdateby("管理员1");
           banner.setUpdateat(time);
           bannerService.insert(banner);
           resultMap.put("code",200);
           resultMap.put("msg","添加成功");
       }catch (Exception e){
resultMap.put("code",404);
           resultMap.put("msg","添加失败");
           e.printStackTrace();
           logger.error("add banner error");
       }
return resultMap;
   }

@DeleteMapping("/Banner/{id}")//删除banner
   @ResponseBody
   public Map<String,Object> deleteBanner(@PathVariable Long id){
logger.info("delete Banner's id is :" + id);
       Map<String,Object> resultMap = new HashMap<>();
       Banner banner = new Banner();
       banner.setId(id);
       try {
if(bannerService.selectBanner(banner).isEmpty()){
resultMap.put("code", 404);
               resultMap.put("msg", "banner不存在!");
           }else {
bannerService.deleteByPrimaryKey(id);
               resultMap.put("code", 200);
               resultMap.put("msg", "删除成功");
           }
}catch (Exception e){
resultMap.put("code",404);
           resultMap.put("msg","删除失败");
           e.printStackTrace();
           logger.error("delete banner error");
       }
return resultMap;
   }

@PutMapping("/Banner/{id}")//编辑banner
   @ResponseBody
   public Map<String,Object> updateBanner(@PathVariable Long id,Banner banner){
logger.info("update banner's id is :" + id);
       Map<String,Object> resultMap = new HashMap<>();
       Banner banner1 = new Banner();
       banner1.setId(id);
       try {
if(bannerService.selectBanner(banner1).isEmpty()){
resultMap.put("code",404);
               resultMap.put("msg","banner不存在");
           }else {
bannerService.updateByPrimaryKeySelective(banner);
               resultMap.put("code", 200);
               resultMap.put("msg", "修改成功");
           }
}catch (Exception e){
resultMap.put("code",404);
           resultMap.put("msg","修改失败");
           e.printStackTrace();
           logger.error("update banner error");
       }
return resultMap;
   }
}
private static final Logger logger = LogManager.getLogger(LeaveController.class);

@Autowired
private LeaveService leaveService;

@GetMapping("/Leave")//查询leave
@ResponseBody
public Map<String,Object> selectleave(Leave leave){
logger.info("select leave is :" + leave);
   Map<String,Object> resultMap = new HashMap<>();
   try {
List<Leave> list = leaveService.selectLeave(leave);
       if(list.isEmpty()){
resultMap.put("code",404);
           resultMap.put("msg","不存在o");
       }else {
resultMap.put("code", 200);
           resultMap.put("msg", "查询成功");
           resultMap.put("data", list);
       }
}catch (Exception e){
resultMap.put("code",404);
       resultMap.put("msg","查询失败");
       e.printStackTrace();
       logger.error("select leave error");
   }
return resultMap;
}

@ResponseBody
@PostMapping("/leave")//新增leave
public Map<String,Object> insertleave(Leave leave){
logger.info("add leave is :" + leave);
   Map<String,Object> resultMap = new HashMap<>();
   try {
Long time = System.currentTimeMillis();
       leave.setCreatat(time);
       leave.setUpdateby("管理员2");
       leave.setUpdateat(time);
       leaveService.insert(leave);
       resultMap.put("code",200);
       resultMap.put("msg","添加leave成功");
   }catch (Exception e){
resultMap.put("code",404);
       resultMap.put("msg","添加失败");
       e.printStackTrace();
       logger.error("add leave error");
   }
return resultMap;
}

@DeleteMapping("/leave/{id}")//删除leave
@ResponseBody
public Map<String,Object> deleteleave(@PathVariable Long id){
logger.info("delete leave's id is :" + id);
   Map<String,Object> resultMap = new HashMap<>();
   Leave leave = new Leave();
   leave.setId(id);
   try {
if(leaveService.selectLeave(leave).isEmpty()){
resultMap.put("code", 404);
           resultMap.put("msg", "leave不存在!");
       }else {
leaveService.deleteByPrimaryKey(id);
           resultMap.put("code", 200);
           resultMap.put("msg", "删除成功");
       }
}catch (Exception e){
resultMap.put("code",404);
       resultMap.put("msg","删除失败");
       e.printStackTrace();
       logger.error("delete leave error");
   }
return resultMap;
}

@PutMapping("/leave/{id}")//编辑leave
@ResponseBody
public Map<String,Object> updateBanner(@PathVariable Long id,Leave leave){
logger.info("update leave's id is :" + id);
   Map<String,Object> resultMap = new HashMap<>();
   Leave leave1 = new Leave();
   leave1.setId(id);
   try {
if(leaveService.selectLeave(leave1).isEmpty()){
resultMap.put("code",404);
           resultMap.put("msg","leave不存在");
       }else {
leaveService.updateByPrimaryKeySelective(leave);
           resultMap.put("code", 200);
           resultMap.put("msg", "修改成功");
       }
}catch (Exception e){
resultMap.put("code",404);
       resultMap.put("msg","修改失败");
       e.printStackTrace();
       logger.error("update leave error");
   }
return resultMap;
}

还有其他的都是差不多的 直接复制了


打包 部署到服务器上 测试通过


明日计划 深度思考

今日问题 暂无


返回列表 返回列表
评论

    分享到