你好,我有更新对象的问题,我不知道如何总是在更新数据后收到消息:不支持请求方法“GET”。但是刷新对象更新后的日期。
使用 GET 和 POST 方法更新对象的 Controller
@Bộ điều khiển
@RequestMapping("/packet")
public class PacketController {
@GetMapping("/modify/{id}")
public String modifyPacketGet(Model model, @PathVariable Long id)
{
model.addAttribute("channels", channelService.getAllChannels());
model.addAttribute("packet", packetService.getById(id));
return "packet/modify";
}
@PostMapping("/modify")
public String modifyPacketPost(Model model, @ModelAttribute PacketDto packetDto)
{
packetService.updatePacket(packetDto);
return "redirect:/packet/modify";
}
HTML 格式
http 请求 GET/packet/modify
未在您的 Controller 中处理,您正在将 BƯU KIỆN
方法重定向到该 http 请求:
return "redirect:/packet/modify";
要解决此问题,您需要执行以下操作之一:
Sẽ BƯU KIỆN
中的重定向请求更改为正在处理的端点:
return "redirect:/packet/modify/" + packetDto.getPacketId();
或者,处理 LẤY
端点:
@GetMapping("/modify/")
public String retrievePacket(...) { ... }
Hy vọng điều này sẽ giúp.
Tôi là một lập trình viên xuất sắc, rất giỏi!