在春季将参数从一个映射传递到另一个

时间:2018-08-29 20:27:32

标签: java spring controller mapping

你好,我在春季将参数从一个映射传递到另一个映射时遇到问题。

@GetMapping("/board")
    public String showBoard(@RequestParam("categoryId") int id, Model theModel) {

        ForumCategory forumCategory = forumService.getForumCategory(id);
        ForumPost forumPost = new ForumPost();
        List<ForumPost> forumPosts = forumCategory.getForumPosts();
        theModel.addAttribute("forumCategory", forumCategory);
        theModel.addAttribute("forumPosts", forumPosts);
        theModel.addAttribute(forumPost);

        return "board";
    }

@PostMapping("/saveForumPost")
    public String saveForumPost(@ModelAttribute("forumPost") ForumPost forumPost, @ModelAttribute("forumCategory") ForumCategory forumCategory) {

        forumService.saveForumPost(forumPost);
        forumService.saveForumCategory(forumCategory);

        return "redirect:/";
    }

所以我要做的是保存forumPost并将其添加到具有/ board映射ID的论坛类别中。有没有办法将参数从/ board映射传递到/ saveForumPost映射?

0 个答案:

没有答案