是否可以通过在属性文件中定义 Spring 中的 @RequestMapping
注释的值来定义它?
实际上,我做了类似的事情:
@Controller
@RequestMapping("/xxx")
public class MyController {
...
}
但我想将路径 /xxx
存储在属性文件中。为什么?例如,如果我重命名 Controller 中的路径,我就不太可能在模板中进行我的操作。
在其他框架中这是允许的(例如,参见 Symfony)。
最佳答案
应该可以在@RequestMapping
中使用占位符,例如@RequestMapping("${foo.bar}")
。看看documentation了解更多详情:
Patterns in
@RequestMapping
annotations support${…
} placeholders against local properties and/or system properties and environment variables. This may be useful in cases where the path a controller is mapped to may need to be customized through configuration. For more information on placeholders, see the javadocs of the PropertyPlaceholderConfigurer class.
关于java - Spring:在属性文件中定义@RequestMapping值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46073581/