@PathParam和@QueryParam

    xiaoxiao2022-07-07  161

    @PathVariable和@RequestParam

    这两个注解是spring框架里的,对于一个http://localhost:8080/user/101?name=xiaoming&age=18

    @Controller public class UserController { @RequestMapping("user/{id}") public String test(@PathVariable(value="id") String aId, @RequestParam(value="name") String aName, @RequestParam(value="age") Integer aAge){ return aId + aName + aAge; } }

    @RequestParam的几个属性值

    defaultValue指定默认值required指定是否必须name和value一样,绑定URL中的参数名,这样一来形参的名字就可以不必跟URL中的参数名一样

    @PathParam和@QueryParam

    这两个注解是在restful接口中常用的,跟上面的两个注解功能一样,只不过上面的两个注解是spring框架里的,这两个是restful框架提供的,一般配合@Path使用,@Path就相当于@RequestMapping。还有@HeaderParam,是从请求的头部中取数据

    最新回复(0)