what is the importance of value attribute in request mappping of post method and this value is co-related in the project in spring mvc?

huangapple go评论53阅读模式
英文:

what is the importance of value attribute in request mappping of post method and this value is co-related in the project in spring mvc?

问题

The "register" word as the value is linked in Spring MVC through the @RequestMapping annotation. In the provided code snippet, @RequestMapping(value = "/register", method = RequestMethod.POST) specifies that this method should be mapped to the "/register" URL path when an HTTP POST request is made to it. This means that when you make a POST request to "/register" in your Spring MVC application, it will invoke the guestUserRegistration method.

英文:

i have a request mapping with post method but i do not know what i should put in value attribute.

@RequestMapping(value = "/register", method = RequestMethod.POST)
public String guestUserRegistration(@RequestHeader(value = "referer", required = false) final String referer,
		final RegisterForm form, final BindingResult bindingResult, final Model model,
		final HttpServletRequest request, final HttpServletResponse response, final RedirectAttributes redirectModel)
		throws CMSItemNotFoundException
{
	logger.info("guest User post method::");
	return processGuestUserRequest(referer, form, bindingResult, model, request, response, redirectModel);
}

How the the "register" word as value is linked in spring mvc?

答案1

得分: 2

The HTTP method parameter has no default – so if you don't specify a value, it's going to map to any HTTP request.

@RequestMapping – by Path

In your example, you are mapping a request by path i.e "/register".

Request Mapping Basics

In Spring MVC applications, the RequestDispatcher (i.e. Front Controller) servlet is responsible for routing incoming HTTP requests to handler methods of controllers. When configuring Spring MVC, you need to specify the mappings between the requests and handler methods.

Test Mapping

To execute this mapping you just need to call this endpoint from your register action button. All API endpoints are relative to the base URL.

For example, assuming the base URL of https://api.example.com/, the /register endpoint refers to https://api.example.com/register.

https://api.example.com/register
\______________________/\____/
         server URL      endpoint path
英文:

The HTTP method parameter has no default – so if you don't specify a value, it's going to map to any HTTP request.

@RequestMapping – by Path

In your example, you are mapping a request by path i.e "/register".

Request Mapping Basics

In Spring MVC applications, the RequestDispatcher (i.e. Front Controller) servlet is responsible for routing incoming HTTP requests to handler methods of controllers. When configuring Spring MVC, you need to specify the mappings between the requests and handler methods.

Test Mapping

To execute this mapping you just need to call this endpoint from your registoer action button. All API endpoints are relative to the base URL.

For example, assuming the base URL of https://api.example.com/, the /registor endpoint refers to https://api.example.com/registor.

https://api.example.com/registor
\______________________/\____/
         server URL      endpoint path

</details>



huangapple
  • 本文由 发表于 2020年8月2日 05:00:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/63210021.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定