java - I would like to ask, can a default value be specified when @PathVariable is empty?
巴扎黑
巴扎黑 2017-05-17 10:06:50
0
2
1178
@RequestMapping(value = "/get/{id}/{userId}", method = RequestMethod.GET)
    public Result getMemberShip(@PathVariable("id") int id,@PathVariable("userId") int userId) {

If id is a non-required parameter and can be empty, how should it be handled? It can be given a default value, or it should not be used in this way. Can java give default values ​​to the passed parameters? I just started writing java, so it is not very easy. clear

巴扎黑
巴扎黑

reply all(2)
習慣沉默

@PathVariable cannot set a default value because null is meaningless for url.
If the parameter may indeed be empty and needs a default value, you can use @RequestParams.

phpcn_u1582

{id}/{userId} If they are not necessary conditions, do not pass parameters like this. It is better to use @ModelAttribute annotation and use objects to pass parameters

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!