69 lines
1.9 KiB
Java
69 lines
1.9 KiB
Java
package com.zoo.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.zoo.common.R;
|
|
import com.zoo.entity.Admin;
|
|
import com.zoo.entity.Animal;
|
|
import com.zoo.service.IAnimalService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* <p>
|
|
* 前端控制器
|
|
* </p>
|
|
*
|
|
* @author DJ
|
|
* @since 2024-05-17
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/zoo/animal")
|
|
public class AnimalController {
|
|
@Autowired
|
|
IAnimalService iAnimalService;
|
|
@GetMapping("/info")
|
|
public R info(Integer aid){
|
|
if (aid != null){
|
|
QueryWrapper<Animal> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("a_id",aid);
|
|
Animal one = iAnimalService.getOne(queryWrapper);
|
|
return R.success(one);
|
|
}
|
|
List<Animal> list = iAnimalService.list();
|
|
return R.success(list);
|
|
}
|
|
@PostMapping("/add")
|
|
public R add(Animal animal){
|
|
boolean save = iAnimalService.save(animal);
|
|
if (save){
|
|
return R.success("添加成功");
|
|
}
|
|
return R.error("添加失败");
|
|
}
|
|
|
|
@PostMapping("/update")
|
|
public R update(Animal animal){
|
|
QueryWrapper<Animal> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("a_id",animal.getaId());
|
|
boolean b = iAnimalService.update(animal,queryWrapper);
|
|
if (b){
|
|
return R.success("修改成功");
|
|
}
|
|
return R.error("修改失败");
|
|
}
|
|
@GetMapping("/delete")
|
|
public R delete(Integer aid){
|
|
QueryWrapper<Animal> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("a_id",aid);
|
|
boolean b = iAnimalService.remove(queryWrapper);
|
|
if (b){
|
|
return R.success("删除成功");
|
|
}
|
|
return R.error("删除失败");
|
|
}
|
|
}
|