import org.springframework.util.Assert;
Assert.isNull(88, "非空就抛出异常吧!");
IllegalArgumentException: 非空就抛出异常吧!
这种方式比if ,else的写法更简洁,可读性也更好,我喜欢!
关于参数校验的方式:
- 1 map接收参数,再使用if else分支校验
- 2使用java对象接收,再加上注解
public JsonResponse getInfo(@RequestParam("id") String id){}
org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'appid' is not present
- 3使用Assert断言