SpringBoot之@RequestParam注解

@RequestParam (org.springframework.web.bind.annotation.RequestParam)用于将指定的请求参数赋值给方法中的形参。
有三个属性:

(1)value:请求参数名(必须配置)

(2)required:是否必需,默认为 true,即 请求中必须包含该参数,如果没有包含,将会抛出异常(可选配置)

(3)defaultValue:默认值,如果设置了该值,required 将自动设为
false,无论你是否配置了required,配置了什么值,都是 false(可选配置)

使用

实现一个删除功能,通过前端在请求路径中传入需要删除的ID

controller层

@GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result<DishVO> getById(@PathVariable Long id) {
        log.info("根据id查询菜品:{}", id);
        DishVO dishVO = dishService.getByIdWithFlavor(id);
        return Result.success(dishVO);
    }

你可能感兴趣的:(springboot小知识,spring,boot,后端,java)