【问题标题】:nested exception is java.lang.NumberFormatException: For input string/ Multipart file and json data to spring boot嵌套异常是 java.lang.NumberFormatException: For input string/ Multipart file and json data to spring boot
【发布时间】:2019-07-18 21:20:48
【问题描述】:

我有 POST 请求 API 调用来接受来自客户端的 JSON 正文请求参数和多部分文件。这是我的方法:

@PostMapping("/saveCategory")
    @ResponseStatus(HttpStatus.OK)
    public void createCategory( @RequestParam("file") MultipartFile file,@RequestParam("cateogry") CategoryModel category) {
        String fileName = fileStorageService.storeFile(file);

        String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath().path("/downloadFile/")
                .path(fileName).toUriString();
        //category.setImage_path(fileName);

        //this.categoryRepository.save(category);

        // return new UploadFileResponse(fileName, fileDownloadUri,
        // file.getContentType(), file.getSize());

    }

我有这个例外:

 "category_name": "ziska111"

    }'; nested exception is java.lang.NumberFormatException: For input string: "{"category_name":"ziska111"}"]

这是我的邮递员请求:

我认为我的CategoryModel 有问题,但我不知道为什么: 这是我的 CategoryModel:

   @Entity
   @Table(name = "Category")
   @JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class CategoryModel {
    @Id
    @Column(name = "id")
//@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String category_name;
private String category_description;
private String image_path;

@JsonIgnore
@OneToMany( mappedBy = "category")
private Set<ProductModel> category;
+Geterrs and Setters

【问题讨论】:

    标签: java spring-boot postman


    【解决方案1】:

    您尝试将字符串转换为整数,但输入字符串包含字母字符,无法转换为整数

    【讨论】:

    • 嗯,我怎样才能从我的邮递员那里发送一个对象,而不是字符串?
    • 从您的屏幕截图中可以看出,您已选择类别作为文本,但您将数据作为 Json 传递。这可能是问题所在。请检查同时,您可以在此处检查两者之间的区别:stackoverflow.com/questions/4350753/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    • 2016-05-26
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多