zoukankan      html  css  js  c++  java
  • @RequestBody和@RequestParam的区别

    1、@RequestBody什么时候用

    当请求方式为post请求,且content-type为application-json的时候

    @RequestMapping(value = "register.do", method = RequestMethod.POST)
        @ResponseBody
        public ServerResponseJsonResult register(@RequestBody UserBO userBO) {
            System.out.println(userBO.getUsername());
            return ServerResponseJsonResult.ok();
        }

    备注:如果使用@RequestBody,那么接收参数必须是以对象形式,比如UserBO userBO,不能是sString username这种,不然会报错

    2、@RequestParam

     请求方式既可以是get也可以是post,Content-Type 为 application/x-www-form-urlencoded 

    注解@RequestParam接收的参数是来自HTTP请求体或请求url的QueryString中

        @RequestMapping(value = "/list", method = RequestMethod.POST)
        public IMOOCJSONResult list(@RequestParam String userId) {
            if (StringUtils.isBlank(userId)) {
                return IMOOCJSONResult.errorMsg("");
            }
    }
  • 相关阅读:
    信息的概念
    信息管理学基础
    第一章关键术语
    企业的转变
    国外的信息系统概念
    管理信息系统的基本功能
    人机交互设计-评价输入法-课下作业
    《构建之法》一
    27日进度
    26号进度
  • 原文地址:https://www.cnblogs.com/zhaobao1830/p/14543426.html
Copyright © 2011-2022 走看看