gpt4 book ai didi

java - Spring Boot中@RequestMapping和Locale有什么关系?

转载 作者:行者123 更新时间:2023-12-02 09:24:01 24 4
gpt4 key购买 nike

如果我的理解是正确的,您可以自由添加/删除 saveEmployee() 的参数。例如,当您按如下方式添加“loc”时,saveEmployee() 在事件发生时会收到“非空对象”。 queryParams 也是如此。

@Controller
public class Employee {
@RequestMapping("/save")
public void saveEmployee(Locale loc,
@RequestParam Map<String, String> queryParams) {
// saving employee
}
}

这个方法如何通过在此处添加参数“loc”来接收非空 Locale 对象?我想知道这背后的逻辑。

最佳答案

Spring 通过使用 LocaleResolverLocaleContextResolver 为您完成此操作,对于当前请求区域设置,由可用的最具体的区域设置解析器确定,实际上,在 MVC 环境中配置 LocaleResolver/LocaleContextResolver

21.3.3 Defining @RequestMapping handler methods

An @RequestMapping handler method can have a very flexible signatures. The supported method arguments and return values are described in the following section. Most arguments can be used in arbitrary order with the only exception of BindingResult arguments.

Supported method argument types

java.util.Locale for the current request locale, determined by the most specific locale resolver available, in effect, the configured LocaleResolver / LocaleContextResolver in an MVC environment.

关于java - Spring Boot中@RequestMapping和Locale有什么关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58470252/

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