diff --git a/build.gradle b/build.gradle index 227b6d5..cb55cf4 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ configurations { dependencies { compile group: 'org.springframework.boot', name: 'spring-boot-starter-web' compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty' + compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf' compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner' compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5' diff --git a/src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java b/src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java new file mode 100644 index 0000000..6b02876 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/mvc/GitExtractorController.java @@ -0,0 +1,43 @@ +package ru.ulstu.extractor.mvc; + +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.servlet.ModelAndView; +import ru.ulstu.extractor.mvc.model.EmailForm; + +import javax.servlet.http.HttpServletRequest; + +@Controller +public class GitExtractorController { + @GetMapping("/") + public String indexForm(Model model) { + model.addAttribute("emailForm", new EmailForm()); + return "index"; + } + + @PostMapping("/sendEmail") + public String sendEmail(@ModelAttribute EmailForm emailForm, Model model) { + if (emailForm.getTo().isEmpty()) { + model.addAttribute("error", "'Кому' не должно быть пустым"); + return "index"; + } + return "result"; + } + + + @ExceptionHandler(Exception.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + public ModelAndView handleResourceNotFoundException(HttpServletRequest req, Exception ex) { + ModelAndView mav = new ModelAndView(); + mav.addObject("exception", ex); + mav.addObject("url", req.getRequestURL()); + mav.setViewName("error"); + return mav; + } +} diff --git a/src/main/java/ru/ulstu/extractor/mvc/model/EmailForm.java b/src/main/java/ru/ulstu/extractor/mvc/model/EmailForm.java new file mode 100644 index 0000000..59765ee --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/mvc/model/EmailForm.java @@ -0,0 +1,40 @@ +package ru.ulstu.extractor.mvc.model; + +public class EmailForm { + private String subject; + private String to; + private String message; + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return "EmailForm{" + + "subject='" + subject + '\'' + + ", to='" + to + '\'' + + ", message='" + message + '\'' + + '}'; + } +} diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html new file mode 100644 index 0000000..dd06612 --- /dev/null +++ b/src/main/resources/templates/error.html @@ -0,0 +1,53 @@ + + + + + +
++ Page: Page URL +
+ ++ Occurred: Timestamp +
+ ++ Response Status: status-code error ... +
+ +
+ Exception: exception
+
+ Application has encountered an error. Please contact support on
+ ... Support may ask you to right click to view page source.
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html
new file mode 100644
index 0000000..f37aa8f
--- /dev/null
+++ b/src/main/resources/templates/index.html
@@ -0,0 +1,30 @@
+
+
+
+ Форма
+
+
+
diff --git a/src/main/resources/templates/result.html b/src/main/resources/templates/result.html
new file mode 100644
index 0000000..08a784e
--- /dev/null
+++ b/src/main/resources/templates/result.html
@@ -0,0 +1,25 @@
+
+
+
+ Результат обработки формы
+
+
+Отправить другое сообщение
+
+
+
+ Тема:
+
+
+
+ Кому:
+
+
+
+Сообщение:
+
+