【问题标题】:how can I do a post with thymeleaf with spring 4 mvc from a table?我怎样才能用 thymeleaf 和桌子上的 spring 4 mvc 做一个帖子?
【发布时间】:2018-08-30 20:43:59
【问题描述】:

我的页面 reg_clientes.html 上有一个 DataTable

<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 (NOT FOUND) clientes / reg_clients / delete ...当我按下表的删除按钮时

我能帮帮我吗?

【问题讨论】:

    标签: javascript jquery ajax spring-mvc thymeleaf


    【解决方案1】:

    看到错误信息我建议将delete的requestMapping改成如下

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

    【讨论】:

      猜你喜欢
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 2021-03-17
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多