【发布时间】: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