@RequestParam和@RequestMapping之间的差异 [英] diffrence between @RequestParam and @RequestMapping

查看:48
本文介绍了@RequestParam和@RequestMapping之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第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 时对 @RequestParam @RequestMapping 感到困惑 @RequestMapping .以我的理解,两者都会将 custId 的值分配给 customerId 数据成员.

i am going thorough my project code and having some confusion in @RequestParam and @RequestMapping some times i found @RequestParam and some times @RequestMapping. in my understanding both will assign the value of custId to customerId data member.

我的jsp文件的一部分:

some part of my jsp file:

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

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

for better understanding of my problem i have done editting in Line2

推荐答案

您将苹果与梨进行比较.这两个注释没有什么共同之处,只是这是Spring MVC注释,并且您对 @RequestMapping("categoryName")的使用是错误

You compare apples with pears. Both annotations have nothing in common except that this are Spring MVC annotations, and your usage of @RequestMapping("categoryName") is wrong!

  • @RequestMapping 是用于将请求url映射到java方法的类或方法注释.
  • @RequestParam 是(方法)字段注释,用于将请求参数绑定到方法参数
  • @RequestMapping is an class or method annotation to map the request url to the java method.
  • @RequestParam is a (Method) field annotation to to bind a request parameter to an method parameter

也许您将 @RequestMapping @PathVariable 混搭了,您的问题是关于 @RequestParam 的区别@PathVariable -然后查看此 answer .

Maybe you mashed @RequestMapping with @PathVariable, and your question is about the difference of @RequestParam and @PathVariable - then have a look at this answer.

这篇关于@RequestParam和@RequestMapping之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆