【问题标题】:@RequestParam to pass pojo fields in spring boot from form-data of postman@RequestParam 从邮递员的表单数据中传递 Spring Boot 中的 pojo 字段
【发布时间】:2019-03-20 05:06:53
【问题描述】:

我已经在 Spring Boot 中进行了发布映射,以从 postman 的表单数据中传递我的 pojo 的所有字段值。 其中一个字段涉及上传由 multipartfile 处理的文件。

运行此方法时,我在邮递员中收到内部服务器错误

@RequestMapping(method=RequestMethod.POST,value="/upload/{jobID}")
    public Application upload(@RequestParam("file") MultipartFile file,@PathVariable String jobID,
            @RequestParam("name") String name,@RequestParam("emailId") String emailId,
            @RequestParam("applicationStatus") ApplicationStatus applicationStatus) throws IOException {

        Offer offer=offerRepository.findById(jobID).get();
        Application application=new Application();
        System.out.println(file.getContentType());
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        application.setApplicationStatus(ApplicationStatus.valueOf("APPLIED"));
        application.setResume(file.getBytes());
        application.getMykey().setOffer(offer);


        return applicationRepository.save(application); 
    }

这里是详细的错误

{
    "timestamp": "2018-10-15T17:31:31.346+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "No message available",
    "path": "/api/upload/SE"
}

【问题讨论】:

  • 您的方法似乎调用正确,因此处理过程中出现问题,因此检查报价来自 db 或 application.getMykey() 是否正确或保存方法..

标签: json spring-boot postman


【解决方案1】:

尝试使用 POJO 作为 requestParams 来组织方法输入 看 http://dolszewski.com/spring/how-to-bind-requestparam-to-object/

在获得可选测试(如果存在)之前 if(optional.isPresent()) 然后 optional.get()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-11
    • 2021-01-24
    • 1970-01-01
    相关资源
    最近更新 更多