今天在跟前端联调一个新的接囗时遇到这个错误  ,错误代码 

  1.  
    /**
  2.  
    * 扫描车牌号码得到车辆信息
  3.  
    * @param plateId
  4.  
    * @return
  5.  
    */
  6.  
    @RequestMapping(value = "scanPlateNumber")
  7.  
    @ResponseBody
  8.  
    public ResponseResult scanPlateNumber(@RequestBody Integer plateId) {
  9.  
    VehicleEntity vehicleEntity;
  10.  
    try{
  11.  
    logger.info("批次发货--添加车牌id:"+plateId);

因为@RequestBody是将post请求中content值转为一个整体对象。@RequestBody的解析有两个条件: 
1.POST请求中content的值必须为json格式(存储形式可以是字符串,也可以是byte数组); 
2.@RequestBody注解的参数类型必须是完全可以接收参数值的类型,比如:Map,JSONObject,或者对应的JavaBean; 
所以Integer类型不能作为@RequestBody注解的参数类型,将上述代码修改如下(前端改成get请求)即可: 
 

  1.  
     /**
  2.  
         * 扫描车牌号码得到车辆信息
  3.  
         * @param plateId
  4.  
         * @return
  5.  
         */
  6.  
        @RequestMapping(value = "scanPlateNumber")
  7.  
        @ResponseBody
  8.  
        public ResponseResult scanPlateNumber(@RequestParam Integer plateId) {
  9.  
            VehicleEntity vehicleEntity;
  10.  
            try{
  11.  
                logger.info("批次发货--添加车牌id:"+plateId);
  12.  
                vehicleEntity = vehicleDAO.findVehicleById(plateId);

 
 下面总结下我所在做项目常用接囗格式: 

     1.post请求,参数通常为一个javaBean

  1.  
        /**
  2.  
         * 包裹发货(中心仓)
  3.  
         * @param orderPackageDeliveryParam
  4.  
         * @return
  5.  
         */
  6.  
        @RequestMapping("deliveryOrderPackage")
  7.  
        @ResponseBody
  8.  
        public ResponseResult deliveryOrderPackage(@RequestBody OrderPackageDeliveryParam orderPackageDeliveryParam) {
  9.  
            try {
  10.  
                List<OrderPackageDeliveryVo> orderPackageAllEntityList = orderPackageDeliveryParam.getOrderPackageDeliveryVo();

    2.get请求 

a.参数放在url里(旧的接囗常用)

  1.  
    /**
  2.  
         * 扫描仓位码得到仓位信息
  3.  
         * @param cityId
  4.  
         * @return
  5.  
         */
  6.  
        @RequestMapping(value = "scanWarehousePositionCode/{cityId}")
  7.  
        @ResponseBody
  8.  
        public ResponseResult scanWarehousePositionCode(@PathVariable("cityId") Long cityId) {
  9.  
            TimeAddressEntity timeAddressEntity;
  10.  
            try {
  11.  
                timeAddressEntity = timeAddressService.findTimeAddressWarehouseById(cityId);

                b.参数放在url后

    1.  
       /**
    2.  
           * 扫描车牌号码得到车辆信息
    3.  
           * @param plateId
    4.  
           * @return
    5.  
           */
    6.  
          @RequestMapping(value = "scanPlateNumber")
    7.  
          @ResponseBody
    8.  
          public ResponseResult scanPlateNumber(@RequestParam Integer plateId) {
    9.  
              VehicleEntity vehicleEntity;
    10.  
              try{
    11.  
                  logger.info("批次发货--添加车牌id:"+plateId);
    12.  
                  vehicleEntity = vehicleDAO.findVehicleById(plateId);