Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 405-请求GET和POST_Java_Spring_Rest_Spring Boot_Spring Mvc - Fatal编程技术网

Java 405-请求GET和POST

Java 405-请求GET和POST,java,spring,rest,spring-boot,spring-mvc,Java,Spring,Rest,Spring Boot,Spring Mvc,您好,我有更新对象的问题,我不知道更新数据后我有消息:请求方法“GET”不受支持。但刷新对象之后的日期是update 使用GET和POST方法更新对象的控制器 @Controller @RequestMapping("/packet") public class PacketController { @GetMapping("/modify/{id}") public String modifyPacketGet(Model model, @PathVariable Lon

您好,我有更新对象的问题,我不知道更新数据后我有消息:请求方法“GET”不受支持。但刷新对象之后的日期是update

使用GET和POST方法更新对象的控制器

@Controller
@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表单

        <form th:action="@{/packet/modify}" method="post" th:object="${packet}" enctype="multipart/form-data">
            <input type="text" hidden="hidden" readonly="readonly" th:field="*{id}" />
            <input type="text" hidden="hidden" readonly="readonly" th:field="*{filename}" />
            <div class="form-group">
                <label for="name" class="h3 text-success">Name:</label>
                <input id="name" type="text" th:field="*{name}" class="form-control">
            </div>
            <div class="form-group">
                <label for="price" class="h3 text-success">Price:</label>
                <input id="price" type="text" th:field="*{price}" class="form-control">
            </div>
            <div class="form-group">
                <label for="description" class="h3 text-success">Description:</label>
                <textarea class="form-control" rows="5" th:field="*{description}" id="description"></textarea>
            </div>
            <div class="form-group">
                <label for="image" class="h3 text-success">Image:</label>
                <input id="image" type="file" th:field="*{multipartFile}"  accept="image/**" class="form-control">
            </div>
            <div class="form-group">
                <label for="channel" class="h2 text-secondary">Channels:</label>
                <ul class="list-inline">
                    <li  class="list-inline-item" th:each="c : ${channels}">
                        <input id="channel" type="checkbox" th:field="*{channelIds}" th:value="${c.id}">
                        <label th:text="${c.name}"></label>
                    </li>
                </ul>
            </div>

                <button type="submit" class="btn btn-success btn-lg mr-2">Add</button>
        </form>

姓名:
价格:
说明:
图片:
频道:
添加
控制器中未处理http请求
GET/packet/modify
,您正在将
POST
方法重定向到该http请求:

        return "redirect:/packet/modify";
要解决此问题,您需要执行以下操作之一:

  • POST
    中的重定向请求更改为正在处理的端点:

        return "redirect:/packet/modify/" + packetDto.getPacketId();
    
  • 或者,处理
    GET
    端点:

        @GetMapping("/modify/")
        public String retrievePacket(...) { ... }
    
  • 希望这有帮助