简体   繁体   English

使用 @Value 将值传递给 @RequestParam

[英]Pass value with @Value to @RequestParam

So basically I have my rootFolderId in my application.properties所以基本上我的 application.properties 中有我的 rootFolderId

  app.property.rootFolder="some string "

and I need to get it in the Controller我需要把它放在 Controller

 @Value("${app.property.rootFolder}")
    private static  String rootFolder ;

and use it in @RequestParam like:并在@RequestParam 中使用它,例如:

@GetMapping({"/list"})
    public List<File> list(@RequestParam(defaultValue = rootFolder)  String parentId) 
{ ..../}

but I get the problem "Attribute value must be constant".Is there any way to make it work?但我得到了问题“属性值必须是恒定的”。有什么办法让它工作吗?

You can use property replacement in the @RequestParam field.您可以在@RequestParam字段中使用属性替换。 See below.见下文。

@GetMapping({"/list"})
public List<File> list(@RequestParam(defaultValue = "${app.property.rootFolder}") String parentId) { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM