一个controller能同时使用两个@requestbody吗

看图:

controller层

    @RequestMapping("/testJson")
    public void testJson(@RequestBody Product product, String gender, @RequestBody ProductOrder order){
    
    
        System.out.println(order);
        System.out.println(gender);
        System.out.println(product);

    }

控制台打印

 at [Source: (PushbackInputStream); line: 2, column: 1]]
2021-01-21 09:34:35.777  WARN 15168 --- [nio-8081-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `com.techman.tmy.entity.Product` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.techman.tmy.entity.Product` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 2, column: 1]]

实体类Product

package com.techman.tmy.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;
@Data
public class Product {
    
    
    private  int id;
    private String category;
    private String name;
    private  String productNo;
    private   String description;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8" )
    private Date createTime;

}

实体类ProductOrder

package com.techman.tmy.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;
@Data
public class ProductOrder {
    
    
    private int id;
    private int productId;
    private int editionId;
    private String orderNo;
    private String status;
    private String description;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8" )
    private Date createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8" )
    private  Date modifyTime;}`  

猜你喜欢

转载自blog.csdn.net/bryangp/article/details/112916495