Spring:使用RequestMapping映射字符串和数字

时间:2013-07-09 20:55:48

标签: java spring hibernate

我在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,但它似乎只适用于实体,在这种情况下我没有唯一的实体,只有两个简单的参数。

1 个答案:

答案 0 :(得分:0)

使用@RequestParam注释:

@RequestMapping("/addprice")
public String addPrice(@RequestParam String name, @RequestParam double price) 
{
    // function code
}