`
passion99
  • 浏览: 11156 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

http之RequestMapping

    博客分类:
  • http
阅读更多

1、@requestMapping

未明确指定Method时,支持所有请求方法类型。但入参未用@RequestBody指明情况下,只能接收url上的查询参数Params、或者form-data(字符键值对或文件)、。不能接收body参数/x-www-form-urlencoded等。

 

@RequestMapping("all")

public void testHttpRequest(HttpServletRequest request, HttpServletResponse response,@RequestBody TUser tUser);

 

2、GET方法是否可以使用body传参的问题

经验证,实际是可以使用body传参。但http协议上对GET方法进行body传参,没有明确的语义定义。实际上不建议这么做。

因为已有的实现框架,有的不支持GET使用body传参,有的支持(如elasticSearch API),统一在自己的系统中避免使用即可。

 

参考:

https://stackoverflow.com/questions/978061/http-get-with-request-body

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET

 

 

3、URL上直接拼接查询参数和x-www-form-urlencoded的区别

 

URL上直接拼接会显示在浏览器地址栏上,对于中文等特殊字符,需要进行urlencode编译,以免后台不能识别

x-www-form-urlencoded是在body中传,也不会显示在浏览器地址栏上,私密性更好

 

 

分享到:
评论

相关推荐

    Spring 实现远程访问详解——httpclient

    说得简单就是直接通过spring requestmapping即请求映射url访问远程服务。 1. 远程访问流程 1) 服务器在控制器定义远程访问请求映射路径 2) 客户端通过apache httpclient的 httppost方式访问远程服务 2. Httpclient...

    springmvc-RequestMapping:根据映射的 URL 定位具有 @RequestMapping 注释的整个类或特定处理程序方法

    springmvc-RequestMapping 根据映射的 URL 定位具有 @RequestMapping 注释的整个类或特定处理程序方法目的 : 大多数时候,当我们不熟悉基于 spring 框架的 Web 应用程序时,我们只有一种选择来定位 Controller 类或...

    SpringMVC-SSH全注解

    import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.org.core.entity.User; import com.org.core.service.UserService; import ...

    SpringHATEOAS.zip

    @RequestMapping("/people") class PersonController { @RequestMapping(method = RequestMethod.GET) public HttpEntity<PersonResource> showAll() { … } @RequestMapping(value = "/{person}", method = ...

    Spring2.5_基于注解驱动的SpringMVC

    @RequestMapping 注解中除了 params 属性外,还有一个常用的属性是 method,它可以让 Controller 方法处理特定 HTTP 请求方式的请求,如让一个方法处理 HTTP GET 请求,而另一个方法处理 HTTP POST 请求,如下所示:...

    Logincontroller.java

    import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.mchange.v2.c3p0.ComboPooledDataSource; @Controller @RequestMapping...

    SpringMVC文件上传下载

    @RequestMapping(value="/file") public class FileController { @Resource private User user; @RequestMapping(value="/toUpload") public String toUpload(){ return "/upload"; } @RequestMapping...

    springmvc02.zip

    使用方法直接下载导入到自己的eclipse工具中,tomcat进行部署,访问地址:http://ip:port/springmvc02/toLogin.do;将login.jsp中的form表单中的action请求路径修改为LoginController类中的相应的@RequestMapping("/...

    Java微服务库QBit.zip

    是一个 Reactive 编程库用于构建微服务,包括 JSON, HTTP, WebSocket 和 REST 等。性能:示例代码:@RequestMapping("/adder-service") public class AdderService {  @RequestMapping("/add/{0}/{1}")  ...

    springboot jpa mysql controller演示

    * http://localhost:8080/helloboot * @return */ @RequestMapping("/hellotest") public String helloTest(){ return "Hello!"; } /** * htmltest * @return */ @RequestMapping("/htmltest") ...

    springmvc的一个简单实例

    import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class HelloController { @RequestMapping("/Login.jsp") public ...

    SpringBoot视频教程 快速上手

    第一节:@RequestMapping配置url映射 第二节:@Controller处理http请求 第三节:@RestController处理ajax请求 第四节:@PathVariable获取url参数 第五节:@RequestParam获取请求参数 第四章:SpringBoot之Spring ...

    license.txt

    我们在springmvc中使用json经常出现乱码格式 如下图: 我们可以在@RequestMapping()中配置,produces = "application/... <bean class="org.springframework.http.converter.StringHttpMessageConverter">

    gale:基于Netty和HTTP的高性能RPC框架

    import im.dadoo.gale.http.annotation.RequestMapping;import im.dadoo.gale.http.request.GaleRequest;import im.dadoo.gale.http.request.RequestMethod;@Controllerpublic class BookController { @...

    feign-1.0.0.jar

    @RequestMapping(value = "/${path}",method = RequestMethod.GET) Map,Object> sendBaiduGet(@PathVariable(value = "path") String path, @RequestParam(value = "param") String param,@RequestParam(value = ...

    Bootstrap分页

    @RequestMapping(value="/delUser.do",method={RequestMethod.POST,RequestMethod.GET},consumes="application/json; charset=UTF-8") @ResponseBody public ModelAndView delUser(@RequestParam(required = true...

    spring-web-5.3.6 jar包.rar

    这个jar文件包含Web应用开发时...包括一些动载入Web ApplicationContext 特性的类、Lister类、文件上传的支持类、便捷的工具辅助类、Spring HTTP调用、用于集成其他web框架的基础结构以及技术,例如(@RequestMapping)

    java sring mvc 及页面提交传参

    import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; /** * ...

    netty-http-server:这是一个基于流行的netty项目和spring框架的非常轻便的http服务器

    定义一个控制器类来处理请求@Controller@RequestMapping ( value = " /api/10 " )public class TestCtrl {@RequestMapping ( value = " /test1 " )public Object test1 ( @RequestBody Test1Req test1 ) {

Global site tag (gtag.js) - Google Analytics