Answer the question
In order to leave comments, you need to log in
How to save an image in the table when changing other fields?
There is a table where the data from the form is pulled in which there are several text input fields and one input field with the "file" type (the picture is loaded there).
The problem is that if you change something other than the picture, the picture will not be saved after updating the data.
Here is the table (it's on the index.mustache page (template engine)
<table class="table_col">
<tr>
<th>Код ошибки</th>
<th>Описание</th>
<th>Номер заявки(Naumen)</th>
<th>Номер задачи (Jira)</th>
<th>Старый номер задачи(Jira)</th>
<th>Изображение</th>
<th>Решение</th>
<th>Статус</th>
<th>Дата</th>
</tr>
{{#RECORD}}
<tr>
<td bgcolor="#6759EE" id="maintd">{{tag}}</td>
<td style="white-space:pre; ">{{description}}</td>
<td>{{naumen}}</td>
<td>{{jiraID}}</td>
<td>{{oldjiraID}}</td>
<td><a href="/downloadfile/{{id}}"><img src="/downloadfile/{{id}}" width="180" height="180"></a></td>
<td style="white-space:pre; ">{{resolution}}</td>
<td >{{status}}</td>
<td>{{date}}</td>
<td><a href="edit/{{id}}">изменить</a></td>
<td><a href="delete/{{id}}">удалить</a></td>
</tr>
{{/RECORD}}
</table>
<div class="divtextform">
<form action="/editrecordform" enctype="multipart/form-data" method="post" class="contact_form">
<input type="hidden" name="id" value="{{#editrec}}{{id}}{{/editrec}}" >
<label for="tag">Код ошибки:</label> <input type="text" name="tag" value="{{#editrec}}{{tag}}{{/editrec}}">
<br>
<label for="description">Описание:</label><textarea name="description" id="" cols="100" rows="10" wrap="hard">{{#editrec}}{{description}}{{/editrec}}</textarea>
<br>
<label for="naumen">Номер в Naumen:</label> <input type="text" name="naumen" value="{{#editrec}}{{naumen}}{{/editrec}}">
<br>
<label for="jiraID">ID в JIRA:</label> <input type="text" name="jiraID" value="{{#editrec}}{{jiraID}}{{/editrec}}">
<br>
<label for="oldJiraID">ID в JIRA (архив):</label> <input type="text" name="oldjiraID" value="{{#editrec}}{{oldjiraID}}{{/editrec}}">
<br>
<label for="resolution">Решение:</label><textarea name="resolution" id="" cols="100" rows="10" wrap="hard"></textarea>
<br>
<button type="submit">изменить</button>
</form>
</div>
@GetMapping("/downloadfile/{id}")
public ResponseEntity<ByteArrayResource> downloadFile(@PathVariable Integer id){
Piro piro = repos.findById(id).get();
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(piro.getDoctype()))
.header(HttpHeaders.CONTENT_DISPOSITION,"attachment:filename=\""+piro.getDocname()+"\"")
.body(new ByteArrayResource(piro.getData()));
}
@GetMapping("edit/{id}")
public String editRecord(@PathVariable Integer id,Map <String,Object> model){
Piro piro=repos.getOne(id);
model.put("editrec",piro);
return "editrecord";
}
@PostMapping("/editrecordform")
public String getEditedInfo(@RequestParam Integer id, @RequestParam String description, @RequestParam String tag, @RequestParam String naumen, @RequestParam String jiraID, @RequestParam String oldjiraID,@RequestParam String resolution ) throws IOException {
Piro piro=repos.getOne(id);
piro.setDescription(description);
piro.setTag(tag);
piro.setNaumen(naumen);
piro.setJiraID(jiraID);
piro.setOldjiraID(oldjiraID);
piro.setResolution(resolution);
try {
piro.setStatus(restClient.getJiraStatus(piro.getJiraID()));
}
catch (HttpClientErrorException e){
piro.setStatus("не известно");
} catch (JSONException e) {
e.printStackTrace();
}
piro.setDate(datev);
repos.save(piro);
return "redirect:/";
}
@PostMapping("fillform")
public String addData(@RequestParam String description,@RequestParam String tag,@RequestParam String naumen,@RequestParam String jiraID, @RequestParam String oldJiraID, @RequestParam MultipartFile file, @RequestParam String resolution){
try {
Piro data = new Piro(description, tag, naumen, jiraID, oldJiraID, file.getBytes(),resolution, file.getOriginalFilename(),file.getContentType(),datev);
try {
data.setStatus(restClient.getJiraStatus(data.getJiraID()));
}
catch (HttpClientErrorException e){
data.setStatus("не известно");
}
repos.save(data);
}
catch (Exception e) {
e.printStackTrace();
}
return "redirect:/";
}
Answer the question
In order to leave comments, you need to log in
How to save an image in the table when changing other fields?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question