@Select("select * from user where uid = #{uid} and uname = #{uname}")
List<User> getUserList(@Param("uid") Integer id, @Param("uname") String name);
1.@Param
主要用于Dao层注解中的sql语句有多条条件参数,且和方法的参数名称不一致,此时可以用@Param注解
只有一个参数时,可以不使用注解(建议使用,养成好习惯)参数的顺序无关
2.@RequestParam
@RequestMapping(value = "/user/get", method = RequestMethod.POST)
public List<User> getUserList(@RequestParam("uid") Integer id, @RequestParam("uname") String name) {
}
`
@RequestParam 主要用在controller层
``
前端提交的form表单数据中的属性名和方法中的参数名不一致时 ,springMVC就无法自动封装参数,所以需要 @RequestParam("前端所传属性名") 来指定前端提交的表单的属性的名称
前端提交的form表单数据中的属性名和方法中的参数名一致时,可以不使用此注解
3.@PathVariable
据说@PathVariable 是RSET风格的springmvc取值。
@RequestMapping("/user/{uid}")
public User getUserById(@PathVariable("uid") Long uid) {
特点:
应用在Controller层
@PathVariable是spring3.0的一个新功能:可接收请求路径中占位符的值,通过 @PathVariable 可以将URL中占位符参数{uid}绑定到处理器类的方法形参uid中 —— @PathVariable(“uid“)
请求路径中占位符的名字可与方法参数名不一样:public User getUserById(@PathVariable(“uid”) Long id)
1994

被折叠的 条评论
为什么被折叠?



