springboot/springmvc @PathVariable接收参数可能为null

 /**
     * 查询课程下的班级
     */
    @RequestMapping(value = {"/infoCourseClass/{schoolId}/{courseId}", "/infoCourseClass/{schoolId}/{courseId}/{classId}"})
    public Result infoCourseClass(Long schoolId, Long courseId, Long classId);

由于接手的项目,需要在原来的基础上修改,涉及到@PathVariable接收的参数可能为null的情况

    @Override
    public Result infoCourseClass(@PathVariable("schoolId") Long schoolId,
                                  @PathVariable("courseId") Long courseId,
                                  @PathVariable(required = false) Long classId) {
        // 调用
    }

总结两步:

一、@RequestMapping,加可能为null的可能性url

二、@PathVariable(required = false) Long classId,加required = false

两步就ok啦,剩下的就是业务逻辑问题

你可能感兴趣的:(springboot/springmvc @PathVariable接收参数可能为null)