4

在@RequestMapping属性文件中定制路径 | baeldung

 2 years ago
source link: https://www.jdon.com/60872
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在@RequestMapping属性文件中定制路径 | baeldung
在本教程中,我们将了解如何在属性文件中 设置@RequestMapping值。此外,我们将使用一个实际示例来解释所有必要的配置。

代码:

@RestController
@RequestMapping("/${welcome-controller.path}")
public class WelcomeController {
    @GetMapping
    public String getWelcomeMessage() {
        return "Welcome to Baeldung!";
    }
}

需要自己创建属性文件。我们将它放在资源文件夹中并将其命名为application.properties。
然后,我们必须使用我们选择的名称创建属性。
在我们的例子中,我们将设置名称welcome-controller.path 并将我们想要的值设置为请求的端点。

welcome-controller.path=welcome

效果:
curl http://localhost:9006/welcome 
> Welcome to Baeldung!

本文的完整源代码可 在 GitHub 上获得。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK