POST和GET方法的URL相同.当链接到URL时如何选择哪一个

same URL for a POST and GET method. How to choose which one when linking to the URL?

本文关键字:URL 何选择 哪一个 选择 链接 方法 GET 相同 POST      更新时间:2023-09-26

我有一个GET和POST方法,我想控制使用哪一个。它们是:

@RequestMapping(value="/greeting", method=RequestMethod.GET)
    public String greetingForm(Model model) {
        model.addAttribute("greeting", new Greeting());
        return "greeting";
    }
    @RequestMapping(value="/greeting", method=RequestMethod.POST)
    public String greetingSubmit(@ModelAttribute Greeting greeting, Model model) {
        model.addAttribute("greeting", greeting);
        return "result";
    }

GET方法启动HTML文件greeting . HTML, POST方法启动result.html。正如你所看到的,它们都有相同的路径(/Greeting)。

在另一个HTML文件中,我希望能够链接到/问候,但我希望能够选择GET或POST方法。这可能吗?

这段代码来自另一个html文件,我想链接到GET或POST方法:

<a href="/greeting">Go to greetings.html </a> 
<a href="/greeting">Go to result.html</a>

如何使第一个链接到GET方法,第二个链接到POST方法,同时保持它们在相同的url上?

第二行

<form action='./greetings' method='post'><INPUT TYPE='submit' name='' value='Goto result.html'/></form>

请注意,第二行显示为按钮,而不是超链接。