Skip to content
Advertisement

Pass value with @Value to @RequestParam

So basically I have my rootFolderId in my application.properties

  app.property.rootFolder="some string "

and I need to get it in the Controller

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

and use it in @RequestParam like :

@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 ?

Advertisement

Answer

You can use property replacement in the @RequestParam field. See below.

@GetMapping({"/list"})
public List<File> list(@RequestParam(defaultValue = "${app.property.rootFolder}") String parentId) { ... }
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement