如何通过控制器访问RESTController?

时间:2017-11-30 03:40:23

标签: rest spring-mvc

我正在使用Spring。

我的RESTController中的方法是这样的, http://localhost:8080/delivery-api/training/submit。它能够将硬代码值保存到数据库中。

这是我的html表单的一部分,可以使用以下网址打开:http://localhost:8080/delivery-web/training/apply

<form th:object="${applyForm}" class="form-horizontal" role="form" method="post" action="http://localhost:8080/delivery-api/training/submit" >



                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right"
                            for="form-field-1" > Country </label>

                        <div class="col-sm-9">
                            <input type="text" id="form-field-1" placeholder="Country"
                                class="col-xs-10 col-sm-7" th:field="*{country}" />
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right"
                            for="form-field-1"> Fee </label>

                        <div class="col-sm-9">
                            <input type="text" id="form-field-1" th:field="*{Fee}"              class="col-xs-10 col-sm-7" />
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right"
                            for="form-field-1"> Start Date </label>

                        <div class="col-sm-9">
                            <input type="date" id="form-field-1" th:field="*{startDate}"

                                class="col-xs-10 col-sm-7" />
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right"
                            for="form-field-1">End Date </label>

                        <div class="col-sm-9">
                            <input type="date" id="form-field-1" th:field="*{endDate}"

                                class="col-xs-10 col-sm-7" />
                        </div>
                    </div>


                    <br> <br>

                    <button class="btn btn-info" type="submit">
                                <i class="ace-icon fa fa-check bigger-110"></i> Submit
                            </button>
                        </div>
                    </div>
                </form>

当我点击提交时,可以将其定向到http://localhost:8080/delivery-api/training/submit并将硬编码值插入数据库,但之后没有指向我的application-form.html页面。

我的控制器

@PostMapping(value = "/apply")
    public String apply(@Valid @ModelAttribute("applyForm") DeliveryApplicationForm applyForm, BindingResult errors, Model model) {


        model.addAttribute("applyForm", applyForm);


        return VIEW_PATH + "application-form";
    }

我想在我的html页面中单击提交按钮后,渲染html页面并通过控制器将数据从我的表单传递到RESTController方法。

我可以知道怎么做吗?

0 个答案:

没有答案
相关问题