您当前的位置: 首页 > 

梁云亮

暂无认证

  • 4浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

redirect重定向Controller中方法之间传递参数

梁云亮 发布时间:2020-07-31 10:32:24 ,浏览量:4

相关博客:关于RedirectAttributes 重定向带参数请求问题 示例
@PostMapping("/upate/{id}")
public String update(@PathVariable("id")Integer id,Category category,RedirectAttributes attributes) {
    int saveRes = categoryService.update(id,category);
    if (saveRes == 1) {//成功
        attributes.addFlashAttribute("msg", "恭喜,修改成功!");
    } else {//失败
        attributes.addFlashAttribute("msg", "恭喜,修改失败!");
    }
    return "redirect:/admin/category/list";  //重定向
}

@GetMapping("/list")
public String list(@ModelAttribute("msg") String msg,Model model) {
    PageBean categoryIPage = categoryService.listPage(pageNum, pageSize);
    if(msg == null) {
        model.addAttribute("msg", "恭喜,查询成功!");
    }
    model.addAttribute("data", categoryIPage);
    return "/admin/category";
}

在list方法中使用@RequestParam:注解不能获取到重定向传递过来的参数,使用@ModelAttribute可以获取数据。

关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0426s