参数请求未返回实际值

时间:2019-04-17 17:14:17

标签: java spring-boot

我有一个表格,该表格不存在于表单中,但是我希望每一行中的按钮相互关联,并在单击该行时从该表格行中删除该联系人。我可以进行ajax调用,但我希望通过Spring Boot Controller方法来处理它。这就是我的设置方式。

@RequestMapping(value="/removeContact")
public String removeContact(final CarrierAppointment carrierAppointment, final HttpServletRequest req, Model model){
    final Integer rowId = Integer.valueOf(req.getParameter("trashContact"));
    carrierAppointment.getContactList().remove(rowId.intValue());
    model.addAttribute("carrierAppointment", carrierAppointment);
    return  "redirect:/carrierAppointment/details/"+carrierAppointment.getId();
}

                        <table class="table table-striped" data-classes="table-no-bordered" data-striped="true" data-show-columns="true" >
                            <thead>
                            <tr>
                                <th>Contact Type</th>
                                <th>Contact Name</th>
                                <th>Contact's Email</th>
                                <th>Contact's Phone</th>
                                <th></th>
                                <th th:if="${role.isCarrierAdmin}" class="text-right"><a class="trigger-add-contact btn btn-default" id="addCommercialContact" name="addCommercialContact"><span class="fa fa-plus"></span></a></th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="contact,stat : *{carrier.contactList}" th:if="*{carrier.contactList[__${stat.index}__].contactTable}=='Commercial Lines'">
                                <td>
                                    <select class="form-control" th:field="*{carrier.contactList[__${stat.index}__].contactType}">
                                        <option value="Account Manager">Account Manager</option>
                                        <option value="Marketing Manager">Marketing Manager</option>
                                        <option value="Underwriter">Underwriter</option>
                                    </select>
                                </td>
                                <td> <input type="text" class="form-control" th:field="*{carrier.contactList[__${stat.index}__].contactName}"/></td>
                                <td> <input type="text" class="form-control" th:field="*{carrier.contactList[__${stat.index}__].contactEmail}"/></td>
                                <td><input type="text" class="form-control" th:field="*{carrier.contactList[__${stat.index}__].contactPhone}"/></td>
                                <td> <input type="hidden" value='Commercial Lines' th:field="*{carrier.contactList[__${stat.index}__].contactTable}"/></td>
                                <td class="text-right" th:if="${role.isCarrierAdmin}"> <button type="button" name="trashContact" th:value="${stat.index}" th:onclick="'window.location.href=\'/removeContact\''"  class="btn btn-danger "><span class="fa fa-trash"></span></button></td>
                            </tr>
                            </tbody>
                        </table>

请求参数并获取值的代码行是我的代码挂起的地方。它返回null而不是值。知道如何调整这行代码,以便实际上获得存在的值吗? 也许是我设置onclick的方式,实际上不是将行值发送到控制器方法吗?

这正是它在代码中挂起的位置:

    public String getParameter(String name) {
        this.handleQueryParameters();
        ArrayList<String> values = (ArrayList)this.paramHashValues.get(name);
        if (values != null) {
            return values.size() == 0 ? "" : (String)values.get(0);
        } else {
            return null;
        }
    }

0 个答案:

没有答案