fix image upload
This commit is contained in:
parent
0f500266bc
commit
beb5fd2e15
BIN
data/db.mv.db
BIN
data/db.mv.db
Binary file not shown.
@ -39,15 +39,18 @@ public class NewsService {
|
|||||||
|
|
||||||
public void save(News news) throws IOException {
|
public void save(News news) throws IOException {
|
||||||
String fileName = System.currentTimeMillis() + "";
|
String fileName = System.currentTimeMillis() + "";
|
||||||
news.setImageFileName(fileName);
|
if (!news.getImageFile().isEmpty()) {
|
||||||
|
news.setImageFileName(fileName);
|
||||||
|
FileUtil.saveFile(FileSystemStorageService.UPLOAD_DIR, fileName, news.getImageFile());
|
||||||
|
} else {
|
||||||
|
news.setImageFileName(news.getImageFileName().isEmpty() ? "logo.png" : news.getImageFileName());
|
||||||
|
}
|
||||||
|
|
||||||
if (news.getId() != null && (news.getId() != 0)) {
|
if (news.getId() != null && (news.getId() != 0)) {
|
||||||
newsRepository.save(news);
|
newsRepository.save(news);
|
||||||
} else {
|
} else {
|
||||||
create(news);
|
create(news);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUtil.saveFile(FileSystemStorageService.UPLOAD_DIR, fileName, news.getImageFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public News getById(@NotNull Integer id) {
|
public News getById(@NotNull Integer id) {
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<input type="hidden" th:field="*{id}">
|
<input type="hidden" th:field="*{id}">
|
||||||
<input type="hidden" th:field="*{date}">
|
<input type="hidden" th:field="*{date}">
|
||||||
<input type="hidden" th:field="*{version}">
|
<input type="hidden" th:field="*{version}">
|
||||||
|
<input type="hidden" th:field="*{imageFileName}">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="title">Заголовок</label>
|
<label for="title">Заголовок</label>
|
||||||
<input type="text" class="form-control" id="title" th:field="*{title}" placeholder="Заголовок новости">
|
<input type="text" class="form-control" id="title" th:field="*{title}" placeholder="Заголовок новости">
|
||||||
|
Loading…
Reference in New Issue
Block a user