gpt4 book ai didi

java - 关于Spring MVC中请求映射的一些疑惑

转载 作者:行者123 更新时间:2023-11-30 03:28:28 26 4
gpt4 key购买 nike

我正在学习Spring MVC,在学习 Material 上我有以下问题,我对此有一些疑问:

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?

  • /rewardsonline/admin/accounts/show

  • /admin/accounts/show

  • /accounts/show

  • /show

我认为正确的答案是/accounts/show,我的理由如下:rewardsonline是应用程序名称(应用程序上下文名称 是应用程序名称**。

/admin/accounts/servlet映射,最后show是请求映射(映射到特定方法)。

推理正确还是我遗漏了什么?

最佳答案

你的假设是正确的

给定这个 web.xml 片段

<servlet-mapping>
<servlet-name>your org.springframework.web.servlet.DispatcherServlet</servlet-name>
<url-pattern>/admin/*</url-pattern>
</servlet-mapping>

在你的类里面你必须写

@RequestMapping(value = "/accounts/show", method = RequestMethod.GET)
...your method starts here

将类方法映射到单个 url

记得放这个

<context:component-scan base-package="the package of the classes you want to map"/>

在你的 spring 配置中

关于java - 关于Spring MVC中请求映射的一些疑惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29647953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com