发表于: 2025-06-28 20:42:01
0 6
今天完成的事情:(一定要写非常细致的内容,比如说学会了盒子模型,了解了Margin)
package org.example.controller;
import org.example.model.ApiResponse;
import org.example.model.Link;
import org.example.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/link") // Changed from "/model" to "/link"
public class LinkController { // Changed from ModelController to LinkController
@Autowired
private LinkService linkService; // Changed from ModelService to LinkService
@GetMapping("/search")
public ApiResponse<List<Link>> queryUser(Long modelId, Long roleId) {
return ApiResponse.success(linkService.getByCondition(modelId, roleId));
}
@GetMapping("/all")
public ApiResponse<List<Link>> getAllLinks() { // Changed return type and method name
List<Link> links = linkService.getAllLinks();
return ApiResponse.success(links);
}
@PutMapping("/{id}")
public ApiResponse<Map<String, Object>> updateLink(@PathVariable Long id, @RequestBody Link link) { // Changed parameter type
try {
link.setId(id);
boolean success = linkService.updateLink(link);
if (success) {
Map<String, Object> response = new HashMap<>();
response.put("id", id);
return ApiResponse.success(response);
} else {
return ApiResponse.error(500, "更新失败,请检查ID是否存在或字段是否有改动");
}
} catch (Exception e) {
e.printStackTrace();
return ApiResponse.error(400, "更新失败: " + e.getMessage());
}
}
@PostMapping("/")
public ApiResponse<Long> insertLink(@RequestBody Link link) { // Changed parameter type
return ApiResponse.success(linkService.insertLink(link));
}
@DeleteMapping("/{id}")
public ApiResponse<Boolean> deleteLink(@PathVariable Long id) { // Changed method name
return ApiResponse.success(linkService.deleteLink(id));
}
}
明天计划的事情:(一定要写非常细致的内容)
遇到的问题:(遇到什么困难,怎么解决的)
收获:(通过今天的学习,学到了什么知识)
评论