表单POST请求不提交给控制器,但GET请求正常

问题描述 投票:-1回答:1

我正在尝试向控制器提交POST请求,但控制器没有响应我的请求,也没有抛出任何错误,但GET请求正常。

我正在使用

<button type="submit" class="btn btn-primary">Submit</button>

在控制器发送我的请求,这将是处理我的请求的控制器>>

@GetMapping("/flexfieldkeysegment/{keyFlexFieldSegmentId}")
public String editCategoryForm(@PathVariable Integer keyFlexFieldSegmentId, Model model) {
    String tenantName=getCurrentTenant().getUser().getTenantName();
    FlexFieldKeySegment segment = keySegment.findFlexFieldKeySegmentById(tenantName, keyFlexFieldSegmentId);
    model.addAttribute("keySegment",segment);
    return viewPrefix+"edit_flexfield_key_segment";
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:th="http://www.thymeleaf.org"
    xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
    layout:decorate="~{layout}">
<body>
    <div layout:fragment="content">
        <br /> <br /> <br />
        <div class="col-md-6 col-md-offset-3">
            <h3 class="sub-title theme-font"></h3>
            <div class="panel panel-primary theme-font">
                <div class="panel-heading">
                    <h3 class="panel-title">Accounting Flexfield Key Segment</h3>
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-12">
                            <form th:action="@{/flexfieldkeysegment/{keyFlexFieldSegmentId}(keyFlexFieldSegmentId=${keySegment.keyFlexFieldSegmentId})}"
                                th:object="${keySegment}" method="post"
                                enctype="multipart/form-data">
                                <p th:if="${#fields.hasErrors('global')}" th:errors="*{global}"
                                    th:class="text-red">Incorrect data</p>
                                <!-- text input -->

                                <div class="form-group"
                                    th:classappend="${#fields.hasErrors('keyFlexFieldSegmentCode')}? 'has-error'">
                                    <label>Flexfield Segment Code <span style="color: red;">*</span></label>
                                    <input type="text" class="form-control"
                                        name="keyFlexFieldSegmentCode"
                                        th:field="*{keyFlexFieldSegmentCode}"
                                        placeholder="Enter Flexfield Key Segment Code" />
                                    <p th:if="${#fields.hasErrors('keyFlexFieldSegmentCode')}"
                                        th:errors="*{keyFlexFieldSegmentCode}" th:class="text-red">Incorrect
                                        data</p>
                                </div>

                                <div class="form-group"
                                    th:classappend="${#fields.hasErrors('name')}? 'has-error'">
                                    <label>Flexfield Key Segment Name<span
                                        style="color: red;">*</span></label> <input type="text"
                                        class="form-control" name="name" th:field="*{name}"
                                        placeholder="Enter Flexfield Key Segment Name" />
                                    <p th:if="${#fields.hasErrors('name')}" th:errors="*{name}"
                                        th:class="text-red">Incorrect data</p>
                                </div>

                                <div class="form-group"
                                    th:classappend="${#fields.hasErrors('description')}? 'has-error'">
                                    <label>Description<span style="color: red;">*</span></label> <input
                                        type="text" class="form-control" name="description"
                                        th:field="*{description}"
                                        placeholder="Enter Flexfield Key Segment Description" />
                                    <p th:if="${#fields.hasErrors('description')}"
                                        th:errors="*{description}" th:class="text-red">Incorrect
                                        data</p>
                                </div>
                                <div class="form-group"
                                    th:classappend="${#fields.hasErrors('separatorId')}? 'has-error'">
                                    <label for="segment_separator">Segment Separator <span
                                        style="color: red;">*</span></label> <select name="name"
                                        id="separator" th:field="*{separatorId}"
                                        th:data-validation-message="#{msg.flexfieldkeysegment.separator.mandatory}"
                                        class="form-control dropdown">
                                        <option th:value="''" th:text="'Select'"></option>
                                        <option th:each="separator : ${segment_separator}"
                                            th:text="${separator.separatorName}"
                                            th:value="${separator.separatorId}"></option>
                                    </select>
                                    <p th:if="${#fields.hasErrors('separatorId')}"
                                        th:errors="*{separatorId}" th:class="text-red">Incorrect
                                        data</p>
                                </div>

                                <div class="form-group">
                                    <div style="width: 30%; float: left; margin-right: 3%;">
                                        <input type="checkbox" th:field="*{freezeFlexfieldDefinition}"
                                            th:value="${freezeFlexfieldDefinition}" /> <label>Freeze
                                            Flexfield Definition</label>
                                    </div>
                                    <div style="width: 30%; float: left; margin-right: 3%;">
                                        <input type="checkbox" th:field="*{crossValidateSegment}"
                                            th:value="${crossValidateSegment}" /> <label>Cross
                                            Validate Segment</label>
                                    </div>
                                    <div style="width: 30%; float: left; margin-right: 3%;">
                                        <input type="checkbox" th:field="*{freezeRollUpGroup}"
                                            th:value="${freezeRollUpGroup}" /> <label>Freeze
                                            Rollup Group</label>
                                    </div>
                                    <div style="width: 30%; float: left; margin-right: 3%;">
                                        <input type="checkbox" th:field="*{allowDynamicInsert}"
                                            th:value="${allowDynamicInsert}" /> <label>Allow
                                            Dynamic Insert</label>
                                    </div>
                                    <div style="width: 30%; float: left; margin-right: 3%;">
                                        <input type="checkbox" th:field="*{active}"
                                            th:value="${active}" /> <label>Active</label>
                                    </div>

                                </div>

                            </form>
                        </div>
                    </div>
                    <div class="box-footer">
                        <button type="button" class="btn btn-warning"
                            onclick="window.history.go(-1); return false;">
                            <span class="glyphicon glyphicon-arrow-left"></span> Back
                        </button>
                        <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>
</html>
spring-boot http-post thymeleaf
1个回答
0
投票

而不是@GetMapping,使用@PostMapping。另外,使用@RequestBody注释'Model'POJO

    @PostMapping("/flexfieldkeysegment/{keyFlexFieldSegmentId}")
    public String editCategoryForm(@PathVariable Integer keyFlexFieldSegmentId, @RequestBody Model model) {
       String tenantName=getCurrentTenant().getUser().getTenantName();
       FlexFieldKeySegment segment = keySegment.findFlexFieldKeySegmentById(tenantName, keyFlexFieldSegmentId);
       model.addAttribute("keySegment",segment);
       return viewPrefix+"edit_flexfield_key_segment";
}
© www.soinside.com 2019 - 2024. All rights reserved.