springmvc注解@RequestParam
作用
修饰参数,将请求参数与控制器参数绑定。
示例
- 控制器示例
@GetMapping
public Page<PostListVO> pageBy(
@PageableDefault(sort = {"topPriority", "createTime"}, direction = DESC) Pageable pageable,
@RequestParam(value = "keyword",required=false) String keyword,
@RequestParam(value = "categoryid",required=false) Integer categoryid) {
PostQuery postQuery = new PostQuery();
postQuery.setKeyword(keyword);
postQuery.setCategoryId(categoryid);
postQuery.setStatus(PostStatus.PUBLISHED);
Page<Post> postPage = postService.pageBy(postQuery, pageable);
return postService.convertToListVo(postPage, true);
}
语法
required:是否必须
defaultValue:默认值,如果设置了默认值required设置为true也无效
@RequestParam(value="参数名称",required="true or false",defaultValue="默认值")
评论区