前后端数据操作

1.前端代码如下

<td>
   <a th:href="@{/user/delete/{id}(id=${user.id})}" class="btn btn-danger btn-sm" type="button">删除a>
td>

当然如果还要停留在删除页,可以携带请求参数(参数为当前页)

<td>
   <a th:href="@{/user/delete/{id}(id=${user.id},p=${uesrs.current})}" class="btn btn-danger btn-sm" type="button">删除a>
td>

2.后端代码如下

 /**
     * 删除数据
     */
    @GetMapping("/user/delete/{id}")

    public String deleteUser(@PathVariable("id") Integer id,@RequestParam(value = "p", defaultValue = "1") Integer p,RedirectAttributes ra) {
        userService.removeById(id);
        ra.addAttribute("p",p);
        return "redirect:/editable_table";
    }

重定向到如下视图

@Autowired
    UserService userService;

    @GetMapping("/editable_table")
    public String editable_table(@RequestParam(value = "p", defaultValue = "1") Integer p, Model model) {
       /* List list = userService.list();
        model.addAttribute("users", list);*/
        //分页查询数据
        Page<User> userPage = new Page<>(p, 5);
        //分页查询的结果
        Page<User> page = userService.page(userPage, null);
        long current = page.getCurrent();
        long pages = page.getPages();
        long total = page.getTotal();
        List<User> records = page.getRecords();
        model.addAttribute("page",page);
        return "table/editable_table";
    }

你可能感兴趣的:(spring,boot,spring,boot,后端,java)