Необходимо добавить пагинацию для новостей и изменить логику контроллера + html

This commit is contained in:
DyCTaTOR 2024-05-24 01:43:09 +04:00
parent 90138ca93d
commit c36a2253f9
13 changed files with 1423 additions and 192 deletions

View File

@ -30,16 +30,19 @@ repositories {
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-validation'
// implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
implementation 'org.modelmapper:modelmapper:3.2.0' implementation 'org.modelmapper:modelmapper:3.2.0'
implementation 'org.springframework.boot:spring-boot-devtools' developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0' implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'org.webjars.npm:bootstrap:5.3.3'
implementation 'com.h2database:h2:2.2.224' implementation 'com.h2database:h2:2.2.224'
runtimeOnly 'org.webjars.npm:bootstrap:5.3.3'
runtimeOnly 'org.webjars.npm:bootstrap-icons:1.11.3'
runtimeOnly 'org.webjars.npm:font-awesome:4.7.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
} }

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,40 +1,40 @@
package com.example.demo.entrysData.api; package com.example.demo.entrysData.api;
public class EntrysDataGroupedDepartmentDto { public class EntrysDataGroupedDepartmentDto {
private String DepartmentName; private String departmentName;
private Long Id; private Long id;
private String Login; private String login;
private String Role; private String role;
public Long getId(){ public Long getId(){
return Id; return id;
} }
public void setId(Long Id){ public void setId(Long Id){
this.Id = Id; this.id = Id;
} }
public String getLogin(){ public String getLogin(){
return Login; return login;
} }
public void setLogin(String Login){ public void setLogin(String Login){
this.Login = Login; this.login = Login;
} }
public String getRole(){ public String getRole(){
return Role; return role;
} }
public void setRole(String Role){ public void setRole(String Role){
this.Role = Role; this.role = Role;
} }
public String getDepartmentName(){ public String getDepartmentName(){
return DepartmentName; return departmentName;
} }
public void setDepartmentName(String DepartmentName){ public void setDepartmentName(String DepartmentName){
this.DepartmentName = DepartmentName; this.departmentName = DepartmentName;
} }
} }

View File

@ -2,7 +2,10 @@ package com.example.demo.entrysData.model;
public interface EntrysDataGroupedDepartment { public interface EntrysDataGroupedDepartment {
Long getId(); Long getId();
String getLogin(); String getLogin();
String getRole(); String getRole();
String getDepartmentName(); String getDepartmentName();
} }

View File

@ -27,8 +27,9 @@ public interface EntrysDataRepository extends CrudRepository<EntrysDataEntity, L
"FROM EntrysDataEntity e " + "FROM EntrysDataEntity e " +
"GROUP BY departmentName ORDER BY count DESC") "GROUP BY departmentName ORDER BY count DESC")
List<EntrysDataGrouped> getCountEntrysInDepartment(); List<EntrysDataGrouped> getCountEntrysInDepartment();
@Query("select e.department.name as departmentName, e.login as login, e.role as role, e.id as id " +
"from EntrysDataEntity e " + @Query("SELECT e.department.name AS departmentName, e.login AS login, e.role AS role, e.id AS id " +
"group by departmentName order by id desc") "FROM EntrysDataEntity e " +
"ORDER BY id DESC")
Page<EntrysDataGroupedDepartment> findAllWithDepartment(Pageable pageable); Page<EntrysDataGroupedDepartment> findAllWithDepartment(Pageable pageable);
} }

View File

@ -127,7 +127,7 @@ td form {
height: 200px; height: 200px;
border: 2px solid #2582A3; border: 2px solid #2582A3;
border-radius: 8%; border-radius: 8%;
margin-left: 180; margin-left: 20%;
margin-top: 9px; margin-top: 9px;
margin-bottom: 25px; margin-bottom: 25px;
} }

View File

@ -9,7 +9,7 @@
<script type="text/javascript" src="/webjars/bootstrap/5.3.3/dist/js/bootstrap.bundle.min.js"></script> <script type="text/javascript" src="/webjars/bootstrap/5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="/webjars/bootstrap/5.3.3/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="/webjars/bootstrap/5.3.3/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="/webjars/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" /> <link rel="stylesheet" href="/webjars/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="/webjars/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/style.css" /> <link rel="stylesheet" href="/css/style.css" />
</head> </head>

View File

@ -9,44 +9,49 @@
<body> <body>
<main class="text-center" layout:fragment="content"> <main class="text-center" layout:fragment="content">
<span class="mainSt"> <th:block th:switch="${departments.size()}">
<b>Кафедры</b> <h2 th:case="0">Данные отсутствуют</h2>
</span> <th:block th:case="*">
<div> <span class="mainSt">
<a href="/departments/edit/" class="btn btn-danger">Добавить кафедру</a> <b>Кафедры</b>
</div> </span>
<table class="table"> <div>
<caption></caption> <a href="/departments/edit/" class="btn btn-danger">Добавить кафедру</a>
<thead> </div>
<tr> <table class="table">
<th scope="col" class="w-10">ID</th> <caption></caption>
<th scope="col" class="w-auto">Название</th> <thead>
<th scope="col" class="w-10"></th> <tr>
<th scope="col" class="w-10"></th> <th scope="col" class="w-10">ID</th>
</tr> <th scope="col" class="w-auto">Название</th>
</thead> <th scope="col" class="w-10"></th>
<tbody> <th scope="col" class="w-10"></th>
<tr th:each="department : ${departments}"> </tr>
<th scope="row" th:text="${department.id}"></th> </thead>
<td th:text="${department.name}"></td> <tbody>
<td> <tr th:each="department : ${departments}">
<form th:action="@{/departments/edit/{id}(id=${department.id})}" method="get"> <th scope="row" th:text="${department.id}"></th>
<button type="submit" class="btn btn-link button-link"> <td th:text="${department.name}"></td>
<i class="fa fa-edit">Изменить</i> <td>
</button> <form th:action="@{/departments/edit/{id}(id=${department.id})}" method="get">
</form> <button type="submit" class="btn btn-link button-link">
</td> <i class="fa fa-edit">Изменить</i>
<td> </button>
<form th:action="@{/departments/delete/{id}(id=${department.id})}" method="post"> </form>
<button type="submit" class="btn btn-link button-link" </td>
onclick="return confirm('Вы уверены?')"> <td>
<i class="fa fa-trash">Удалить</i> <form th:action="@{/departments/delete/{id}(id=${department.id})}" method="post">
</button> <button type="submit" class="btn btn-link button-link"
</form> onclick="return confirm('Вы уверены?')">
</td> <i class="fa fa-trash">Удалить</i>
</tr> </button>
</tbody> </form>
</table> </td>
</tr>
</tbody>
</table>
</th:block>
</th:block>
</main> </main>
</body> </body>

View File

@ -7,8 +7,8 @@
<body> <body>
<main layout:fragment="content"> <main layout:fragment="content">
<form action="#" th:action="@{/directions/edit/{id}(id=${directions.id},(page=${page}))}" th:object="${directions}" <form action="#" th:action="@{/directions/edit/{id}(id=${directions.id},(page=${page}))}"
method="post"> th:object="${directions}" method="post">
<div class="mb-3"> <div class="mb-3">
<label for="id" class="form-label">ID</label> <label for="id" class="form-label">ID</label>
<input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled> <input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
@ -44,7 +44,7 @@
</div> </div>
<div class="mb-3 d-flex flex-row"> <div class="mb-3 d-flex flex-row">
<button class="btn btn-primary me-2 button-fixed-width" type="submit">Сохранить</button> <button class="btn btn-primary me-2 button-fixed-width" type="submit">Сохранить</button>
<a class="btn btn-secondary button-fixed-width" href="/directions(page=${page})">Отмена</a> <a class="btn btn-secondary button-fixed-width" th:href="@{/directions(page=${page})}">Отмена</a>
</div> </div>
</form> </form>
</main> </main>

View File

@ -9,54 +9,62 @@
<body> <body>
<main class="text-center" layout:fragment="content"> <main class="text-center" layout:fragment="content">
<label class="mainSt d-flex justify-content-center" for="direction"> <th:block th:switch="${items.size()}">
Направление</label> <h2 th:case="0">Данные отсутствуют</h2>
<div> <th:block th:case="*">
<a href="/directions/edit/(page=${page})" class="btn btn-danger">Добавить направление</a> <label class="mainSt d-flex justify-content-center" for="direction">
</div> <b>Направление</b>
<table class="table"> </label>
<caption></caption> <div>
<thead> <a th:href="@{/directions/edit/(page=${page})}" class="btn btn-danger">Добавить направление</a>
<tr> </div>
<th scope="col" class="w-5">ID</th> <table class="table">
<th scope="col" class="w-10">Код</th> <caption></caption>
<th scope="col" class="w-25">Направление</th> <thead>
<th scope="col" class="w-25">Кафедра</th> <tr>
<th scope="col" class="w-25">Предметы ЕГЭ</th> <th scope="col" class="w-5">ID</th>
<th scope="col" class="w-5"></th> <th scope="col" class="w-10">Код</th>
<th scope="col" class="w-5"></th> <th scope="col" class="w-25">Направление</th>
</tr> <th scope="col" class="w-25">Кафедра</th>
</thead> <th scope="col" class="w-25">Предметы ЕГЭ</th>
<tbody> <th scope="col" class="w-5"></th>
<tr th:each="direction : ${items}"> <th scope="col" class="w-5"></th>
<th scope="row" th:text="${direction.id}"></th> </tr>
<td th:text="${direction.code}"></td> </thead>
<td th:text="${direction.name}"></td> <tbody>
<td th:text="${direction.departmentName}"></td> <tr th:each="direction : ${items}">
<td th:text="${direction.things}"></td> <th scope="row" th:text="${direction.id}"></th>
<td> <td th:text="${direction.code}"></td>
<form th:action="@{/directions/edit/{id}(id=${direction.id})}" method="get"> <td th:text="${direction.name}"></td>
<input type="hidden" th:name="page" th:value="${page}"> <td th:text="${direction.departmentName}"></td>
<button type="submit" class="btn btn-link button-link"> <td th:text="${direction.things}"></td>
<i class="fa fa-edit">Изменить</i> <td>
</button> <form th:action="@{/directions/edit/{id}(id=${direction.id})}" method="get">
</form> <input type="hidden" th:name="page" th:value="${page}">
</td> <button type="submit" class="btn btn-link button-link">
<td> <i class="fa fa-edit">Изменить</i>
<form th:action="@{/directions/delete/{id}(id=${direction.id})}" method="post"> </button>
<input type="hidden" th:name="page" th:value="${page}"> </form>
<button type="submit" class="btn btn-link button-link" </td>
onclick="return confirm('Вы уверены?')"> <td>
<i class="fa fa-trash">Удалить</i> <form th:action="@{/directions/delete/{id}(id=${direction.id})}" method="post">
</button> <input type="hidden" th:name="page" th:value="${page}">
</form> <button type="submit" class="btn btn-link button-link"
</td> onclick="return confirm('Вы уверены?')">
</tr> <i class="fa fa-trash">Удалить</i>
</tbody> </button>
</table> </form>
<th:block th:replace="~{ pagination :: pagination ( </td>
</tr>
</tbody>
</table>
</th:block>
<th:block th:replace="~{ pagination :: pagination (
url=${'directions'}, url=${'directions'},
totalPages=${totalPages}, totalPages=${totalPages},
currentPage=${currentPage}) }" /> currentPage=${currentPage}) }" />
</th:block>
</main> </main>
</body> </body>
</html>

View File

@ -9,48 +9,93 @@
<body> <body>
<main class="text-center" layout:fragment="content"> <main class="text-center" layout:fragment="content">
<span class="mainSt"> <th:block th:switch="${news.size()}">
<b>Новости</b> <h2 th:case="0">Данные отсутствуют</h2>
</span> <th:block th:case="*">
<div> <span class="mainSt">
<a href="/news/edit/" class="btn btn-danger">Добавить новость</a> <b>Новости</b>
</div> </span>
<table class="table"> <div>
<caption></caption> <a href="/news/edit/" class="btn btn-danger">Добавить новость</a>
<thead> </div>
<tr> <th:block th:unless="${news.size() > 3}">
<th scope="col" class="w-5">ID</th> <div class="row">
<th scope="col" class="w-10">Дата публикации</th> <div class="col mt-4" th:each="newItem : ${news}">
<th scope="col" class="w-25">Заголовок</th> <div class="rectNews d-flex flex-column">
<th scope="col" class="w-50">Описание</th> <img class="imageNew1" src="./images/New1.png" alt th:alt="${newItem.name}"
<th scope="col" class="w-10"></th> width="100%">
<th scope="col" class="w-10"></th> <div class="rectNewsTextBox">
</tr> <span class="rectNewsText">
</thead> <b scope="row" th:text="${newItem.description}"></b>
<tbody> <form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get">
<tr th:each="newItem : ${news}"> <a type="submit" class="btn btn-link button-link">
<th scope="row" th:text="${newItem.id}"></th> <i class="fa fa-edit"></i>
<td th:text="${newItem.date}"></td> </a>
<td th:text="${newItem.name}"></td> </form>
<td th:text="${newItem.description}"></td> <form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post">
<td> <a type="submit" class="btn btn-link button-link"
<form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get"> onclick="return confirm('Вы уверены?')">
<button type="submit" class="btn btn-link button-link"> <i class="fa fa-trash"></i>
<i class="fa fa-edit">Изменить</i> </a>
</button> </form>
</form> </span>
</td> </div>
<td> </div>
<form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post"> </div>
<button type="submit" class="btn btn-link button-link" </div>
onclick="return confirm('Вы уверены?')"> </th:block>
<i class="fa fa-trash">Удалить</i> <th:block th:if="${news.size() > 3}">
</button> <div class="row">
</form> <div class="col mt-4" th:each="newItem : ${news}">
</td> <div class="rectNews d-flex flex-column">
</tr> <img class="imageNew1" src="./images/New1.png" alt th:alt="${newItem.name}"
</tbody> width="100%">
</table> <div class="rectNewsTextBox">
<span class="rectNewsText">
<b scope="row" th:text="${newItem.description}"></b>
<form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get">
<a type="submit" class="btn btn-link button-link">
<i class="fa fa-edit"></i>
</a>
</form>
<form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post">
<a type="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">
<i class="fa fa-trash"></i>
</a>
</form>
</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col mt-4" th:each="newItem : ${news}">
<div class="rectNews d-flex flex-column">
<img class="imageNew1" src="./images/New1.png" alt th:alt="${newItem.name}"
width="100%">
<div class="rectNewsTextBox">
<span class="rectNewsText">
<b scope="row" th:text="${newItem.description}"></b>
<form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get">
<a type="submit" class="btn btn-link button-link">
<i class="fa fa-edit"></i>
</a>
</form>
<form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post">
<a type="submit" class="btn btn-link button-link"
onclick="return confirm('Вы уверены?')">
<i class="fa fa-trash"></i>
</a>
</form>
</span>
</div>
</div>
</div>
</div>
</th:block>
</th:block>
</th:block>
</main> </main>
</body> </body>

View File

@ -9,48 +9,57 @@
<body> <body>
<main class="text-center" layout:fragment="content"> <main class="text-center" layout:fragment="content">
<span class="mainSt"> <th:block th:switch="${items.size()}">
<b>Пользователи</b> <h2 th:case="0">Данные отсутствуют</h2>
</span> <th:block th:case="*">
<div> <span class="mainSt">
<a href="/users/edit/" class="btn btn-danger">Добавить пользователя</a> <b>Пользователи</b>
</div> </span>
<table class="table"> <div>
<caption></caption> <a href="/users/edit/" class="btn btn-danger">Добавить пользователя</a>
<thead> </div>
<tr> <table class="table">
<th scope="col" class="w-5">ID</th> <caption></caption>
<th scope="col" class="w-10">Логин</th> <thead>
<th scope="col" class="w-25">Роль</th> <tr>
<th scope="col" class="w-50">Кафедра</th> <th scope="col" class="w-5">ID</th>
<th scope="col" class="w-10"></th> <th scope="col" class="w-10">Логин</th>
<th scope="col" class="w-10"></th> <th scope="col" class="w-25">Роль</th>
</tr> <th scope="col" class="w-50">Кафедра</th>
</thead> <th scope="col" class="w-10"></th>
<tbody> <th scope="col" class="w-10"></th>
<tr th:each="newItem : ${news}"> </tr>
<th scope="row" th:text="${newItem.id}"></th> </thead>
<td th:text="${newItem.date}"></td> <tbody>
<td th:text="${newItem.name}"></td> <tr th:each="user : ${items}">
<td th:text="${newItem.description}"></td> <th scope="row" th:text="${user.id}"></th>
<td> <td th:text="${user.login}"></td>
<form th:action="@{/news/edit/{id}(id=${newItem.id})}" method="get"> <td th:text="${user.role}"></td>
<button type="submit" class="btn btn-link button-link"> <td th:text="${user.departmentName}"></td>
<i class="fa fa-edit">Изменить</i> <td>
</button> <form th:action="@{/users/edit/{id}(id=${user.id})}" method="get">
</form> <button type="submit" class="btn btn-link button-link">
</td> <i class="fa fa-edit">Изменить</i>
<td> </button>
<form th:action="@{/news/delete/{id}(id=${newItem.id})}" method="post"> </form>
<button type="submit" class="btn btn-link button-link" </td>
onclick="return confirm('Вы уверены?')"> <td>
<i class="fa fa-trash">Удалить</i> <form th:action="@{/users/delete/{id}(id=${user.id})}" method="post">
</button> <button type="submit" class="btn btn-link button-link"
</form> onclick="return confirm('Вы уверены?')">
</td> <i class="fa fa-trash">Удалить</i>
</tr> </button>
</tbody> </form>
</table> </td>
</tr>
</tbody>
</table>
</th:block>
<th:block th:replace="~{ pagination :: pagination (
url=${'users'},
totalPages=${totalPages},
currentPage=${currentPage}) }" />
</th:block>
</main> </main>
</body> </body>