From 3de59503895cec5d77796d737b9da3bf76c44555 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 18 Mar 2021 11:08:56 +0400 Subject: [PATCH] #2 - change filtering --- .../extractor/mvc/GitExtractorController.java | 17 ++++++++++++++++ .../ulstu/extractor/mvc/model/FilterForm.java | 20 +++++++++++++++++++ .../ulstu/extractor/mvc/model/RepoForm.java | 2 +- src/main/resources/templates/error.html | 18 +++++++++-------- src/main/resources/templates/filtering.html | 13 ++++++------ 5 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/mvc/model/FilterForm.java diff --git a/src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java b/src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java index 4d9b72b..4b46dae 100644 --- a/src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java +++ b/src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java @@ -5,6 +5,7 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; +import ru.ulstu.extractor.mvc.model.FilterForm; import ru.ulstu.extractor.mvc.model.RepoForm; @Controller @@ -16,12 +17,28 @@ public class GitExtractorController { return "newRepo"; } + @GetMapping("/filtering") + public String filter(Model model) { + model.addAttribute("filterForm", new FilterForm()); + return "filtering"; + } + @PostMapping("/sendRepo") public String sendRepo(@ModelAttribute RepoForm repoForm, Model model) { + model.addAttribute("filterForm", new FilterForm()); if (repoForm.getRepo() == null || repoForm.getRepo().isEmpty()) { model.addAttribute("error", "'Git' не должно быть пустым"); return "newRepo"; } return "filtering"; } + + @PostMapping("/sendFilter") + public String sendFilter(@ModelAttribute FilterForm filterForm, Model model) { + if (filterForm.getFilter() == null || filterForm.getFilter().isEmpty()) { + model.addAttribute("error", "'Строка' не должно быть пустым"); + return "filtering"; + } + return "resultRepo"; + } } diff --git a/src/main/java/ru/ulstu/extractor/mvc/model/FilterForm.java b/src/main/java/ru/ulstu/extractor/mvc/model/FilterForm.java new file mode 100644 index 0000000..9a3e8d0 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/mvc/model/FilterForm.java @@ -0,0 +1,20 @@ +package ru.ulstu.extractor.mvc.model; + +public class FilterForm { + private String filter; + + public String getFilter() { + return filter; + } + + public void setFilter(String filter) { + this.filter = filter; + } + + @Override + public String toString() { + return "FilterForm{" + + "subject='" + filter + + '}'; + } +} diff --git a/src/main/java/ru/ulstu/extractor/mvc/model/RepoForm.java b/src/main/java/ru/ulstu/extractor/mvc/model/RepoForm.java index 0a86e6e..7f5766f 100644 --- a/src/main/java/ru/ulstu/extractor/mvc/model/RepoForm.java +++ b/src/main/java/ru/ulstu/extractor/mvc/model/RepoForm.java @@ -13,7 +13,7 @@ public class RepoForm { @Override public String toString() { - return "EmailForm{" + + return "RepoForm{" + "subject='" + repo + '}'; } diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html index bb0ca4a..0017912 100644 --- a/src/main/resources/templates/error.html +++ b/src/main/resources/templates/error.html @@ -32,14 +32,16 @@

-
-
${url}
-
${exception.message}
-
    -
  • ${ste}
  • -
-
+

+

${url}
+

+

${exception.message}
+

+
+ \ No newline at end of file diff --git a/src/main/resources/templates/filtering.html b/src/main/resources/templates/filtering.html index e2597e6..c6f7217 100644 --- a/src/main/resources/templates/filtering.html +++ b/src/main/resources/templates/filtering.html @@ -1,14 +1,14 @@ - + Простая обработка формы на Spring MVC
-
+

Фильтровать данные:

По автору

Строки:
- +

+

- +