简体   繁体   English

在 spring 中执行“POST”操作时出错?

[英]Error when performing "POST" operation in spring?

I have sent the data from the angular service class.我已经从 angular 服务类发送了数据。 Here i have sent three parameters letter,documents,empList to the Api for the POST operation这里我发送了三个参数letter,documents,empList给 Api 进行 POST 操作

export class LetterService {

  private baseUrl = 'http://localhost:8080/api/letter';
   constructor(private http: HttpClient) { }

   saveThree(letter: Object,documents: Object,empList: Object): Observable<Object> {
    return this.http.post(`${this.baseUrl}` + `/create`, {letter,documents,empList});
  }

And on the Spring boot side I used this @RequestBody to map the coming JSON data from service.在 Spring 启动端,我使用这个 @RequestBody 来映射来自服务的即将到来的 JSON 数据。 (You may omit the inside logic of the code as error is another thing) : (您可以省略代码的内部逻辑,因为错误是另一回事)

@PostMapping(value = "/letter/create")
    public String postAllThree(@RequestBody LetterDto letterDto,
            @RequestBody List<Document> document,@RequestBody SelectionCustomOfficeDto selectionCustomOfficeDto) {
        
        
        ClkLetter clkLetter=clkLetterRepository.findById((long)1).get();
        
        Selection selection=selectionRepository.findById((long)letterDto.getSelectionNo()).get();
        
        Assessment assessment=assessmentRepository.findById((long)letterDto.getAssessmentNo()).get();
    
        
        
    Letter letter=letterRepository.save(new Letter(clkLetter,letterDto.getInOut(),letterDto.getInOutNo(),letterDto.getInOutDate(),letterDto.getLetterIssuedSubBy(),letterDto.getLetterFile(),letterDto.getRepresentativeName()
                ,selection,assessment));
        
     for(Document docume:document)  {
         
         if(docume.isChecked()) {
             letterDocRepository.save(new LetterDoc(letter,docume,"a"));
         }
     }
        
        return  "success";
    }

The error I am getting is:我得到的错误是:

[org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; [org.springframework.http.converter.HttpMessageNotReadableException:读取输入消息时出现I/O错误; nested exception is java.io.IOException: Stream closed]嵌套异常是 java.io.IOException: Stream closed]

Why am i getting this error ?为什么我收到这个错误? is the parameter i am sending from angular is not matching or anything wrong in my @Postmapping operation?我从 angular 发送的参数是不匹配还是我的 @Postmapping 操作有问题? i saw other articles and questions also but it didn't work .我也看到了其他文章和问题,但没有用。

You are only allowed to have one @RequestBody.您只能拥有一个@RequestBody。 Combine {letter,documents,empList} in one DTO POJO.将 {letter,document,empList} 合并到一个 DTO POJO 中。

public class MyDTO {
    private Object letter;
    private List<Object> documents;
    private List<Object> empList;
// getters and setters
}

For primitive type request parameters you might use @RequestParam and append them in the URL对于原始类型的请求参数,您可以使用 @RequestParam 并将它们附加到 URL 中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring为什么对已注册的错误页面执行POST请求? - Why is Spring performing POST request to the registered error page? 在IBM中执行联合操作时发生错误 - Error occurred while performing the joint operation in IBM 当运算符存储在字符串中时执行数学运算 - Performing math operation when operator is stored in a string 执行子字符串操作时包含分隔符 - Include delimiter when performing substring operation 与tez0.5.2集成时在hive 1.0.0中执行插入操作时出错 - Getting error while performing insert operation in hive 1.0.0 when integrate with tez0.5.2 执行 MockMvc:在 api 后执行 mockMvc 时出错 - performing MockMvc : getting error while performing mockMvc on post api 我在执行发布请求时收到 404 错误代码,但数据已成功插入 spring 启动应用程序上的数据库中 - I am getting 404 error code while performing post request , but the data is successfully getting inserted into the database on spring boot appilcation 在就地执行Elasticsearch Reindex操作时发生服务器错误 - Server error while performing Elasticsearch Reindex in place operation 对Java中的文件执行签名和验证操作时出错 - Error while performing sign and verify operation to a file in Java 使用 Hibernate 执行 CRUD 操作时出错 - Error occurred during performing CRUD operation using Hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM