[英]Some doubts about request mapping in Spring MVC
I am studying for Spring MVC and on the study material I have the following question on which I have some doubts: 我正在为Spring MVC学习,在学习材料上,我有以下疑问,对此我有一些疑问:
Assuming a web application context name of "rewardsonline" , a servlet mapping of /admin/* , and an incoming URL of " "rewardsonline/admin/accounts/show" what is the URL used from Spring MVC request-mapping purpose?
假设Web应用程序上下文名称为“ rewardsonline” ,servlet映射为/ admin / * ,并且传入URL为“ ” rewardsonline / admin / accounts / show“,那么从Spring MVC请求映射目的使用的URL是什么?
/rewardsonline/admin/accounts/show
/ rewardsonline /管理/账户/节目
/admin/accounts/show
/管理/账户/节目
/accounts/show
/帐号/节目
/show
/节目
I think that the correct answer is /accounts/show and I have reason in the following way: rewardsonline is the applcation name (the application context name is the application name**. 我认为正确的答案是/ accounts / show ,我有以下原因: rewardsonline是应用程序名称( 应用程序上下文名称是应用程序名称**。
Whereas /admin/accounts/ is the servlet mapping and finnaly show is the request mapping (mapped on a specific method). / admin / accounts /是Servlet映射 ,finallyly show是请求映射(映射到特定方法)。
Is it reasoning correct or am I missing something? 是推理正确还是我错过了什么?
Your assumptions are correct 你的假设是正确的
given this web.xml fragment 给定这个web.xml片段
<servlet-mapping>
<servlet-name>your org.springframework.web.servlet.DispatcherServlet</servlet-name>
<url-pattern>/admin/*</url-pattern>
</servlet-mapping>
in your classes you must write 在你的课上,你必须写
@RequestMapping(value = "/accounts/show", method = RequestMethod.GET)
...your method starts here
to map class methods to single url 将类方法映射到单个URL
remember to put this 记得把这个
<context:component-scan base-package="the package of the classes you want to map"/>
in your spring configuration 在您的春季配置中
Correct. 正确。 As you said "rewardsonline" is application context.
如您所说,“ rewardsonline”是应用程序上下文。 /admin/* is servlet mapping which means any request coming from /admin/ will be handled by spring mvc.
/ admin / *是servlet映射,这意味着任何来自/ admin /的请求都将由spring mvc处理。 /accounts/show is used for request mapping purpose.
/ accounts / show用于请求映射。 Controller with mapping /accounts/show will handle this request.
映射/ accounts / show的控制器将处理此请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.