[英]How to upload form data along with image in spring boot
我正在研究一個用例,以在 spring 引導中上傳學生詳細信息及其圖像。 實體 class 如下所示。
public class Student{
private int rollNo;
private String name;
// few more fields
@Lob
private byte[] picture;
// getters setters
}
JSP file
<!DOCTYPE html>
<html>
<head>
<title>Student Registration</title>
</head>
<body>
<form action="save" method="post" enctype="multipart/form-data">
<input type="text" name="rollNo"/>
<input type="text" name="name"/>
<!-- some more fields -->
<input type="file" name="picture"/>
<input type="submit" value="Registration">
</form>
</body>
</html>
the very basic idea could be as follows
@RestController
public class ImageUploadController {
@RequestMapping(value="/upload", method=RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Object> uploadFile(@RequestParam(required=true, value="picture") MultipartFile file, @RequestParam(name = "rollNo") String rollNo, @RequestParam(name = "name") String name) {
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.