小言_互联网的博客

@Param @RequestParam @PathVariable 区别

255人阅读  评论(0)

1.@Param 是Mybatis用的 主要是给参数命名,参数命名后就能根据名字得到参数值。假如输入的参数一致可以省略。

import org.springframework.data.repository.query.Param;

import java.util.List;

@Mapper
public interface kchanneltypeMapper {
@Select(“SELECT*From KChannelType where Productid=#{productid}”)
public List getbyproductid(@Param(“productid”) String productid);
}

2.@RequestParam 和 @PathVariable 是 springMVC用的 注解是用于从request中接收请求的,两个都可以接收参数,关键点不同的是@RequestParam 是从request里面拿取值,而 @PathVariable 是从一个URI模板里面来填充

http://localhost:8080/springmvc/hello/101?param1=10¶m2=20

@RequestMapping("/hello/{id}")

public String getDetails(@PathVariable(value="id") String id,

@RequestParam(value="param1", required=true) String param1,

@RequestParam(value="param2", required=false) String param2){

}
拿的地方不一样


转载:https://blog.csdn.net/wlyxtx/article/details/101227959
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场