簡體   English   中英

我如何從一張桌子上用春天4 mvc作百里香葉的貼子?

[英]how can I do a post with thymeleaf with spring 4 mvc from a table?

我的頁面上有一個數據表reg_clientes.html

<tr  th:each="listado : ${lista}">
     <td th:text="${listado.id}">1</td>
     <td th:text="${listado.ci}">1</td>
     <td th:text="${listado.division}">1</td>
     <td th:text="${listado.nombre}">1</td>
     <td th:text="${listado.apellido}">1</td>
     <td th:text="${listado.direccion}">1</td>
     <td th:text="${listado.email}">1</td>
     <td th:text="${listado.telefono}">1</td>
     <td>
           <form method="POST" id="formdelete" >
            <input type="submit" name="submit" value="borrar" class="link-button" th:onclick="'eliminar(\'' + ${listado.id} + '\');'"/>
            </form>
    </td>
                     </tr>

`

delete_ = function(id) {
$.ajax({
    url : 'delete',
    type : 'POST',
    data : {
        id : id
    },
    success : function(response) {
        alert(response.message);

        location.reload();
    }
});

}

function eliminar(id) {
    var statusConfirm = confirm("Realmente desea eliminar esto?");
    if (statusConfirm == true) {
        delete_(id);
    } else {
        load();
    }



return statusConfirm;

ClienteController.java

@RequestMapping("/clientes/reg_clientes")
public String contacts(Model model) {
    model.addAttribute("lista",clienteservice.list());
    return "abm/clientes/reg_clientes";
}

@RequestMapping(value = "/delete", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> delete(Long id) {
    Map<String, Object> map = new HashMap<String, Object>();

    if (clienteservice.delete(id)) {
        map.put("status", "200");
        map.put("message", "Registro eliminado exitosamente");
    }

    return map;
}

但它不起作用,當我按表的刪除按鈕時,它會給出POST錯誤404(找不到)客戶端/ reg_clients /刪除 ...

我可以幫我嗎?

看到錯誤消息,我建議將deleteMapping更改為以下內容

@RequestMapping(value = "/clientes/reg_clientes/delete", method = RequestMethod.POST)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM