Can @PathVariable return null if it’s not found?

They cannot be optional, no. If you need that, you need two methods to handle them.

This reflects the nature of path variables – it doesn’t really make sense for them to be null. REST-style URLs always need the full URL path. If you have an optional component, consider making it a request parameter instead (i.e. using @RequestParam). This is much better suited to optional arguments.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)