Spring Roo Petclinic menu.jspx 和控制器。它是如何运作的?

发布于 2024-10-09 23:35:06 字数 970 浏览 6 评论 0原文

供参考。我确实在 Spring Roo 论坛上发布了此内容,但没有回复。

这是一个新手提出的非常基本的问题。

问题在于控制器如何知道引导菜单链接,例如宠物诊所示例中的以下内容

<menu:item id="i_pet_new" messageCode="global_menu_new" url="/pets?form" z="SwmuMoL7UBbDU/gqHy+t5Tl0Ins="/>

我目前的理解是

@RequestMapping("/pets")

@Controller

 public class PetController {

}

处理 url="/pet" 部分,但是

控制器如何知道如何处理剩余部分?上面写着“?form”的部分?

我之前做过简单的mvc项目,我会在PetController类中包含一些代码,它们会执行如下操作:

@RequestMapping("/helloWorld")

public ModelAndView helloWorld() {

    ModelAndView mav = new ModelAndView();

    mav.setViewName("helloWorld");

    mav.addObject("message", "Hello World!");

    return mav;

}

在当前示例中,没有其他方法来处理 ModelAndView !

感谢您的帮助。

FYI. I did post this on the Spring Roo forum but no reply.

This is a very basic question from a newbie.

The question is concerning how the Controller knows to direct the menu link , such as the following from the petclinic example

<menu:item id="i_pet_new" messageCode="global_menu_new" url="/pets?form" z="SwmuMoL7UBbDU/gqHy+t5Tl0Ins="/>


My current understanding is that the

@RequestMapping("/pets")

@Controller

 public class PetController {

}

Handles the url="/pet" portion but

How does the Controller know how to handle the remaining portion? The portion that says "?form" ?

I have done simple mvc projects before and I would have some code inside of the class PetController that would do something like:

@RequestMapping("/helloWorld")

public ModelAndView helloWorld() {

    ModelAndView mav = new ModelAndView();

    mav.setViewName("helloWorld");

    mav.addObject("message", "Hello World!");

    return mav;

}

In the current example there are no additional methods to handle the ModelAndView !

Thanks for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海蓝天 2024-10-16 23:35:06

您会注意到文件 PetController_Roo_Controller.aj 创建在与 PetController.java 相同的文件夹中。其中包含处理此问题的相关代码。具体来说,

@RequestMapping(params = "form", method = RequestMethod.GET)
    public String PetController.createForm(Model model) {
        model.addAttribute("pet", new Pet());
        return "pets/create";
    }

Roo 会为您处理 CRUD 操作。

You will notice the file PetController_Roo_Controller.aj created in the same folder as PetController.java. This contains the relevant code to handle this. Specifically,

@RequestMapping(params = "form", method = RequestMethod.GET)
    public String PetController.createForm(Model model) {
        model.addAttribute("pet", new Pet());
        return "pets/create";
    }

Roo takes care of the CRUD operations for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文