diff --git a/build.gradle b/build.gradle index f9157cd..4f616f0 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ dependencies { implementation group: 'org.webjars', name: 'font-awesome', version: '4.7.0' implementation group: 'org.webjars', name: 'momentjs', version: '2.24.0' implementation group: 'org.webjars', name: 'bootstrap-glyphicons', version: 'bdd2cbfba0' + implementation group: 'org.webjars', name: 'summernote', version: '0.8.10' testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test' } diff --git a/src/main/java/ru/ulstu/meeting/MeetingController.java b/src/main/java/ru/ulstu/meeting/MeetingController.java index f85eea3..1166961 100644 --- a/src/main/java/ru/ulstu/meeting/MeetingController.java +++ b/src/main/java/ru/ulstu/meeting/MeetingController.java @@ -70,8 +70,7 @@ public class MeetingController { @PostMapping("saveMeeting") @Secured({UserRoleConstants.ADMIN}) - public String saveNews(@Valid @ModelAttribute Meeting meeting, - BindingResult result) { + public String saveNews(@Valid @ModelAttribute Meeting meeting, BindingResult result) { if (result.hasErrors()) { return "editMeeting"; } diff --git a/src/main/java/ru/ulstu/news/News.java b/src/main/java/ru/ulstu/news/News.java index d15e7e7..1c3504d 100644 --- a/src/main/java/ru/ulstu/news/News.java +++ b/src/main/java/ru/ulstu/news/News.java @@ -1,14 +1,12 @@ package ru.ulstu.news; import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.web.multipart.MultipartFile; import ru.ulstu.meeting.Meeting; import ru.ulstu.model.BaseEntity; import javax.persistence.Entity; import javax.persistence.Lob; import javax.persistence.OneToOne; -import javax.persistence.Transient; import javax.validation.constraints.NotEmpty; import java.util.Date; @@ -26,11 +24,6 @@ public class News extends BaseEntity { @NotEmpty(message = "Текст новости не может быть пустым") private String text; - private String imageFileName; - - @Transient - private MultipartFile imageFile; - @OneToOne(mappedBy = "news") private Meeting meeting; @@ -67,22 +60,6 @@ public class News extends BaseEntity { return text; } - public String getImageFileName() { - return imageFileName; - } - - public void setImageFileName(String imageFileName) { - this.imageFileName = imageFileName; - } - - public MultipartFile getImageFile() { - return imageFile; - } - - public void setImageFile(MultipartFile imageFile) { - this.imageFile = imageFile; - } - public Meeting getMeeting() { return meeting; } @@ -90,10 +67,4 @@ public class News extends BaseEntity { public void setMeeting(Meeting meeting) { this.meeting = meeting; } - - public String getPreview() { - return text != null && text.length() > MAX_NEWS_TEXT_PREVIEW_LENGTH - ? text.substring(0, MAX_NEWS_TEXT_PREVIEW_LENGTH) + "..." - : text; - } } diff --git a/src/main/java/ru/ulstu/news/NewsController.java b/src/main/java/ru/ulstu/news/NewsController.java index 5d811b4..a85a47d 100644 --- a/src/main/java/ru/ulstu/news/NewsController.java +++ b/src/main/java/ru/ulstu/news/NewsController.java @@ -21,7 +21,6 @@ import ru.ulstu.model.OffsetablePageRequest; import ru.ulstu.model.UserRoleConstants; import javax.validation.Valid; -import java.io.IOException; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -71,8 +70,7 @@ public class NewsController { @PostMapping("saveNews") @Secured({UserRoleConstants.ADMIN}) - public String saveNews(@Valid @ModelAttribute News news, - BindingResult result) throws IOException { + public String saveNews(@Valid @ModelAttribute News news, BindingResult result) { if (result.hasErrors()) { return "editNews"; } diff --git a/src/main/java/ru/ulstu/news/NewsService.java b/src/main/java/ru/ulstu/news/NewsService.java index 8c3d016..8164f0a 100644 --- a/src/main/java/ru/ulstu/news/NewsService.java +++ b/src/main/java/ru/ulstu/news/NewsService.java @@ -3,13 +3,10 @@ package ru.ulstu.news; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import ru.ulstu.files.FileSystemStorageService; -import ru.ulstu.files.FileUtil; import ru.ulstu.meeting.Meeting; import javax.transaction.Transactional; import javax.validation.constraints.NotNull; -import java.io.IOException; import java.util.Date; import java.util.List; @@ -37,15 +34,7 @@ public class NewsService { return newsRepository.save(news); } - public void save(News news) throws IOException { - String fileName = System.currentTimeMillis() + ""; - 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()); - } - + public void save(News news) { if (news.getId() != null && (news.getId() != 0)) { newsRepository.save(news); } else { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7c55a71..c3506d5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,8 +3,11 @@ spring.main.banner-mode=off logging.level.tech.athene=DEBUG server.port=8080 spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false -spring.servlet.multipart.max-file-size=100000000 -spring.servlet.multipart.max-request-size=100000000 +spring.servlet.multipart.max-file-size=2048MB +spring.servlet.multipart.max-request-size=2048MB +server.tomcat.max-http-form-post-size=2048MB +#server.tomcat.max-swallow-size=2048MB +#server.max-http-header-size=2048MB # go to http://localhost:8080/h2-console spring.datasource.url=jdbc:h2:file:./data/db spring.datasource.driverClassName=org.h2.Driver diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 74915f2..ff14a95 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -6,6 +6,10 @@