60

所花时间:420分钟
博客量:1
代码量:几百
所学知识:体育最后一次比赛,python实验5,团队项目拼接和补充。
@RestController
@RequestMapping("/superior")
@CrossOrigin(origins = "*", maxAge = 3600)
public class SuperiorController {

@Autowired
SuperiorRepository repo;

@PostMapping
public ResponseEntity<?> create(@RequestBody superior superior) {
    try {
        superior saved = repo.save(superior);
        return ResponseEntity.ok(saved);
    } catch (Exception e) {
        return ResponseEntity.badRequest().body("创建失败: " + e.getMessage());
    }
}

@PutMapping("/{inspection_id}")
public ResponseEntity<?> update(
        @PathVariable("inspection_id") int inspectionId,
        @RequestBody superior superior) {
    try {
        superior.setInspection_id(inspectionId);
        superior saved = repo.save(superior);
        return ResponseEntity.ok(saved);
    } catch (Exception e) {
        return ResponseEntity.badRequest().body("更新失败: " + e.getMessage());
    }
}

@GetMapping
public List<superior> superiorList() {
    return repo.findAll();
}

@DeleteMapping("/{inspection_id}")
public ResponseEntity<Map<String, Object>> delete(
        @PathVariable("inspection_id") int inspectionId) {
    try {
        repo.deleteById(inspectionId);
        Map<String, Object> response = new HashMap<>();
        response.put("success", true);
        response.put("deletedId", inspectionId);
        return ResponseEntity.ok(response);
    } catch (Exception e) {
        return ResponseEntity.badRequest()
               .body(Collections.singletonMap("error", e.getMessage()));
    }
}

}

posted @ 2025-05-29 22:17  龚恒。  阅读(12)  评论(0)    收藏  举报