简体   繁体   English

Spring MVC-表单提交没有绑定对象

[英]Spring MVC - Form submit without binding object

Im new to Spring MVC and trying to achive something that seems really simple. 我是Spring MVC的新手,尝试实现似乎非常简单的功能。 However i cannot get it to work or find any relevant examples. 但是我无法使其工作或找到任何相关示例。

Using Spring MCV 3.1 with annotations. 使用带有注释的Spring MCV 3.1。 I have a form with only one select-list in it. 我有一个只有一个选择列表的表单。 When this form is submitted, i want to be able to have the id of the select-value submitted to my controller. 提交此表单后,我希望能够将选择值的ID提交给我的控制器。 Thats it! 而已!

I dont want to wrap this value in a Binding object, i'd just like to send it to the controller, preferably by get like this: http://www.mydomain.com/admin/products?marketId=id 我不想将此值包装在Binding对象中,我只想将其发送到控制器,最好这样获取: http : //www.mydomain.com/admin/products?marketId=id

My Controller looks like this: 我的控制器如下所示:

@RequestMapping(value = "/admin/products", method = RequestMethod.GET)
public ModelAndView getProducts(@RequestParam("marketId") String marketId) {

    ModelMap model = new ModelMap();

    // Logic to find products by marketId is not shown
    // ...

    model.addAttribute("products", products);

    return new ModelAndView("products", model);
}

I have not been able to create a jsp that compiles yet, but this is my latest jsp snippet: 我还无法创建可编译的jsp,但这是我最新的jsp代码段:

<form:form method="GET" action="/admin/products.htms" methodParam="marketId" >
    <form:select path="marketId" items="${marketList}" onchange="this.form.submit();"/>
</form:form>

If anyone could help or point out some relevant examples i would be very grateful! 如果有人可以帮助或指出一些相关的例子,我将不胜感激! I have looked at a lot of examples using a binding object to wrap the form-data, but as you can see im looking for something a bit simpler. 我看过很多使用绑定对象包装表单数据的示例,但是正如您所看到的,我正在寻找更简单的东西。

Cheers! 干杯!

If you don't need features such as object binding and error reporting, you can use plain HTML form instead of <form:form> : 如果您不需要诸如对象绑定和错误报告之类的功能,则可以使用纯HTML表单而不是<form:form>

<form method="GET" action="/admin/products.htms">
    <select name="marketId" onchange="this.form.submit();">
        <c:forEach var = "item" items="${marketList}">
            <option value = "${item}">${item}</option>
        </c:forEach>
    </select>
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM