我在Spring中有以下表格:
<form:form method="post" action="addprice.html" commandName="addprice">
<form:input path="name" />
<form:input path="price" />
<input type="submit" value="<spring:message code="Add price"/>"/>
</form:form>
我需要将参数传递给以下函数:
@RequestMapping("/addprice")
public String addPrice(
// WHAT I NEED TO WRITE HERE?
)
{
// function code
}
为了检索“名称”和“价格”,我需要在上一个函数中的parentesys之间编写什么内容?
我尝试使用@ModelAttribute,但它似乎只适用于实体,在这种情况下我没有唯一的实体,只有两个简单的参数。
答案 0 :(得分:0)
使用@RequestParam
注释:
@RequestMapping("/addprice")
public String addPrice(@RequestParam String name, @RequestParam double price)
{
// function code
}