package com.zoo.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.zoo.common.R; import com.zoo.entity.Health; import com.zoo.service.IHealthService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RestController; import java.util.List; /** *

* 前端控制器 *

* * @author DJ * @since 2024-06-07 */ @RestController @RequestMapping("/com/zoo/health") public class HealthController { @Autowired IHealthService iHealthService; @GetMapping("info") public R info(Integer id, Integer animallId){ QueryWrapper queryWrapper = new QueryWrapper<>(); if (id!=null){ queryWrapper.eq("id",id); Health one = iHealthService.getOne(queryWrapper); return R.success(one); } if (animallId!=null){ queryWrapper.eq("animallId",animallId); List list = iHealthService.list(queryWrapper); return R.success(list); } return R.success(iHealthService.list()); } @PostMapping("/add") public R add(Health health){ boolean save = iHealthService.save(health); if (save){ return R.success("添加成功"); } return R.error("添加失败"); } @PostMapping("/update") public R update(Health health){ boolean update = iHealthService.save(health); if (update){ return R.success("修改成功"); } return R.error("修改失败"); } @GetMapping("/delete") public R delete(Integer id){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("id",id); boolean remove = iHealthService.remove(queryWrapper); if (remove){ return R.success("删除成功"); } return R.error("删除失败"); } }