#2 - add web pages

This commit is contained in:
Anton Romanov 2021-03-17 12:19:03 +04:00
parent 23bcb5e1b7
commit ac9dcaa11d
8 changed files with 97 additions and 108 deletions

View File

@ -5,22 +5,23 @@ 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.EmailForm;
import ru.ulstu.extractor.mvc.model.RepoForm;
@Controller
public class GitExtractorController {
@GetMapping("/")
public String indexForm(Model model) {
model.addAttribute("emailForm", new EmailForm());
return "index";
@GetMapping("/newRepo")
public String indexNewRepo(Model model) {
model.addAttribute("repoForm", new RepoForm());
return "newRepo";
}
@PostMapping("/sendEmail")
public String sendEmail(@ModelAttribute EmailForm emailForm, Model model) {
if (emailForm.getTo().isEmpty()) {
model.addAttribute("error", "'Кому' не должно быть пустым");
return "index";
@PostMapping("/sendRepo")
public String sendRepo(@ModelAttribute RepoForm repoForm, Model model) {
if (repoForm.getRepo() == null || repoForm.getRepo().isEmpty()) {
model.addAttribute("error", "'Git' не должно быть пустым");
return "newRepo";
}
return "result";
return "filtering";
}
}

View File

@ -1,40 +0,0 @@
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 + '\'' +
'}';
}
}

View File

@ -0,0 +1,20 @@
package ru.ulstu.extractor.mvc.model;
public class RepoForm {
private String repo;
public String getRepo() {
return repo;
}
public void setRepo(String repo) {
this.repo = repo;
}
@Override
public String toString() {
return "EmailForm{" +
"subject='" + repo +
'}';
}
}

View File

@ -0,0 +1,25 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<body>
<form name="filtering">
<p><b>Фильтровать данные:</b><Br>
<input type="checkbox" name="browser" value="author"> Автор<Br>
<input type="checkbox" name="browser" value="data"> Дата<Br>
<input type="checkbox" name="browser" value="lineFtom"> Удаленные строки<Br>
<input type="checkbox" name="browser" value="lineTo"> Добавленные строки<Br>
</p>
<p>
<input type="button" value="Отправить" onClick='location.href="result.html"'>
</p>
</form>
</body>
</div>
</html>

View File

@ -1,32 +0,0 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<h1>Форма</h1>
<form action="#" th:action="@{/sendEmail}" th:object="${emailForm}" method="post">
<p style="color:red" th:text="${error}"></p>
<table>
<tr>
<td>Тема:</td>
<td><input type="text" th:field="*{subject}"/></td>
</tr>
<tr>
<td>Кому:</td>
<td><input type="text" th:field="*{to}"/></td>
</tr>
<tr>
<td>Сообщение:</td>
<td><textarea th:field="*{message}"/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Отправить"/></td>
</tr>
</table>
</form>
</div>
</html>

View File

@ -0,0 +1,22 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<body>
<form action="#" th:action="@{/sendRepo}" th:object="${repoForm}" method="post">
<p style="color:red" th:text="${error}"></p>
<p><b>Ваш git репозиторий:</b><br>
<input type="text" size="40" th:field="*{repo}">
</p>
<p>
<input type="submit" value="Отправить"/>
</p>
</form>
</body>
</div>
</html>

View File

@ -1,25 +0,0 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Результат обработки формы</h1>
<table>
<tr>
<td>Тема:</td>
<td><p th:text="${emailForm.subject}"/></td>
</tr>
<tr>
<td>Кому:</td>
<td><p th:text="${emailForm.to}"/></td>
</tr>
<tr>
<td>Сообщение:</td>
<td><p th:text="${emailForm.message}"/></td>
</tr>
</table>
<a href="/">Отправить другое сообщение</a>
</body>
</html>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<body>
<form oninput="result">
<p>Данные репозитория:</p>
<p>
<output name="result"></output>
</form>
</body>
</div>
</html>