0

第 1 行:

public ModelAndView viewCustomerDetails(@RequestParam("custId") Integer customerId, @RequestParam("categoryName") String categoryName, HttpServletRequest request) throws BusinessException{

第 2 行:

public ModelAndView viewCustomerDetails(@RequestMapping("custId") Integer customerId, @RequestMapping("categoryName") String categoryName, HttpServletRequest request) throws BusinessException{

我正在仔细研究我的项目代码,@RequestParam有时@RequestMapping我发现有时@RequestParam有些困惑@RequestMapping。据我了解,两者都会将值分配custIdcustomerId数据成员。

我的jsp文件的一部分:

<form:input mandatory="true" id="CustNameTxt" path="custName" cssClass="txtfield controlWidth" readonly="false" />

为了更好地理解我的问题,我在 Line2 中进行了编辑

4

2 回答 2

6

您将苹果与梨进行比较。除了这是 Spring MVC 注释之外,这两个注释没有任何共同之处,而且您的使用@RequestMapping("categoryName")错误的!

  • @RequestMapping是将请求url映射到java方法的类或方法注解。
  • @RequestParam是一个(方法)字段注释,用于将请求参数绑定到方法参数

也许你捣碎@RequestMapping@PathVariable,你的问题是关于和的区别@RequestParam-@PathVariable然后看看这个答案

于 2015-07-14T06:05:36.563 回答
1

@RequestMapping将请求映射到资源。它用于不在其参数中的方法。来自 SpringByExample

@Controller 表示该类是 Spring MVC 控制器原型,它由 context:component-scan 在 web-application-context.xml 中自动注册。方法上的 @RequestMapping 注解使用 value 属性将方法映射到路径。method 属性用于指示 HTTP 请求类型(例如:GET、POST、DELETE)。

@RequestParam将资源 URL 中的参数绑定到方法中的参数。

于 2015-07-14T05:53:17.813 回答