http://blog.csdn.net/lavorange/article/details/50696936
编写Spring restful api接口是一个非常常用的手段来接受http请求服务,那么接收参数的方法以及使用Mock进行测试可以值得探究一下。
没有请求参数,指定请求路径来接收相应的请求,举个简单的例子:
请求示例:{base}/c/manager/qcs/client/list@RequestMapping:设置了请求的路由路径和方法。其是处理请求地址映射的注解,可用用类或者方法上。在类之上时,表示类中所有的方法对应的请求都是以该映射作为父地址。
@Controller:控制器,也就是Spring MVC里面的"C",也就是Controller。
value:方法对应的请求路径
method:请求对应的方法。有GET,PUT,POST,DELETE,HEAD。
说明一下POST
和PUT
的区别: POST
永远是创建新的。PUT
可以表示创建,但是如果指定的URI存在,则含义为更新。换句话说,一个PUT
请求,重复执行,结果应该是一样的。
@ResponseBody:将内容或对象作为HTTP响应正文返回,使用@ResponseBody会表过视图处理部分,调用适合HttpMessageConverter,将返回值写入输出流。
@RequestParam:请求参数注解,代表方法参数应该与web请求参数绑定。
required:参数是否必须,如果为true则为必须;为false为不必须。
请求路径:{base}/r/qcs/whitelistlogically?entry={a}&volume={b}通过解析HttpServletRequest来获取请求参数。
一般是对于POST请求,通过Json带入需要传入的参数比较多的情况下的数据。
通过一个对象实体来接受请求,然后解析请求对象,然后或许相应的参数。就行解析。对应的路径:{base}/r/qcs/whitelistlogically?entry={entry}&volume={volume}
@PathVariable:注解绑定请求传来的值到方法的参数上。
以上是主要一些spring restful api获取参数的方法,作为以备后续翻阅。
>http://liuyanwei.jumppo.com/2015/05/28/spring-2.html
>http://stackoverflow.com/questions/11291933/requestbody-and-responsebody-spring
注明出处:http://blog.csdn.net/lavorange/article/details/50696936