我的页面上有一个数据表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)

关于javascript - 我如何从一张 table 上用 Spring 4 mvc作 thymeleaf 的贴子?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49411261/

10-10 23:41