@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
習慣沉默2017-05-17 10:08:50
@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_u15822017-05-17 10:08:50
{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