1、@pathVariable
1.1 PathVariable使用案例:
@GetMapping("dept/{id}")
public Department getById(@PathVariable("id" )Integet id )
1.2参数解析:
1、name/value:RequestMapping注解中url路径绑定参数的名称,如/pathVariable/test/{param},则name的值就为param
2、required: 为true时,这个参数必选填写,默认是true,为false时:参数可选是否填写
2.@RequestParam
2.1 Requestparam使用案例
@RequestMapping("/requestParam/user?id=1")
@ResponseBody
public String requestParamTest(@RequestParam(value = "id",required = true,defaultValue = "1")String id){
return "接受到的参数:" + id;
}
2.2 参数解析
RequestParam: 主要用在Controller层,用于获取URL中“?”后携带的参数的值,如:
http://localhost:8080/requestParam/user?id=1中id参数的值
* 相关属性:
* 1、name/value:url中指定参数的名称
* 2、required: 为true时,这个参数必选填写,默认是true,为false时:参数可选是否填写
* 3、defaultValue:参数不填写时的默认值
**/
3.@Parma
3.1 Param使用案例
public List<User> findUser(@Param("userName") String userName, @Param("department") String department);
3.2 参数解析
@Param是MyBatis所提供的(org.apache.ibatis.annotations.Param),主要用于DAO层,作用是用于传递参数,从而可以与SQL中的的字段名相对应,一般在2=<参数数<=5时使用最佳。