学习Spring的@RequestBody和@RequestParam [英] learning Spring's @RequestBody and @RequestParam

查看:125
本文介绍了学习Spring的@RequestBody和@RequestParam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编辑一个使用Spring的Web项目,我需要添加一些Spring的注释。我要添加的其中两个是 @ RequestBody @ RequestParam 。我一直在探索一下,发现这个,但我仍然不完全了解如何使用这些注释。有人可以提供一个例子吗?

I'm editing a web project that uses Spring and I need to adding some of Spring's annotations. Two of the ones I'm adding are @RequestBody and @RequestParam. I've been poking around a little and found this, but I still don't completely understand how to use these annotations. Could anyone provide an example?

推荐答案

控制器示例:

@Controller
class FooController {
    @RequestMapping("...")
    void bar(@RequestBody String body, @RequestParam("baz") baz) {
        //method body
    }
}

@ RequestBody 变量正文将包含HTTP请求的正文

@RequestBody: variable body will contain the body of the HTTP request

@ RequestParam 变量baz将保留请求参数baz

@RequestParam: variable baz will hold the value of request parameter baz

这篇关于学习Spring的@RequestBody和@RequestParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆