#2 - add web pages
This commit is contained in:
parent
23bcb5e1b7
commit
ac9dcaa11d
@ -5,22 +5,23 @@ import org.springframework.ui.Model;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import ru.ulstu.extractor.mvc.model.EmailForm;
|
import ru.ulstu.extractor.mvc.model.RepoForm;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class GitExtractorController {
|
public class GitExtractorController {
|
||||||
@GetMapping("/")
|
|
||||||
public String indexForm(Model model) {
|
@GetMapping("/newRepo")
|
||||||
model.addAttribute("emailForm", new EmailForm());
|
public String indexNewRepo(Model model) {
|
||||||
return "index";
|
model.addAttribute("repoForm", new RepoForm());
|
||||||
|
return "newRepo";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/sendEmail")
|
@PostMapping("/sendRepo")
|
||||||
public String sendEmail(@ModelAttribute EmailForm emailForm, Model model) {
|
public String sendRepo(@ModelAttribute RepoForm repoForm, Model model) {
|
||||||
if (emailForm.getTo().isEmpty()) {
|
if (repoForm.getRepo() == null || repoForm.getRepo().isEmpty()) {
|
||||||
model.addAttribute("error", "'Кому' не должно быть пустым");
|
model.addAttribute("error", "'Git' не должно быть пустым");
|
||||||
return "index";
|
return "newRepo";
|
||||||
}
|
}
|
||||||
return "result";
|
return "filtering";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
20
src/main/java/ru/ulstu/extractor/mvc/model/RepoForm.java
Normal file
20
src/main/java/ru/ulstu/extractor/mvc/model/RepoForm.java
Normal 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 +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
25
src/main/resources/templates/filtering.html
Normal file
25
src/main/resources/templates/filtering.html
Normal 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>
|
@ -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>
|
|
22
src/main/resources/templates/newRepo.html
Normal file
22
src/main/resources/templates/newRepo.html
Normal 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>
|
@ -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>
|
|
18
src/main/resources/templates/resultRepo.html
Normal file
18
src/main/resources/templates/resultRepo.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user