thymeleaf index.html
This commit is contained in:
parent
45dfaf5f5c
commit
297e4b4029
6
pom.xml
6
pom.xml
@ -34,10 +34,16 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.thymeleaf.extras</groupId>
|
||||||
|
<artifactId>thymeleaf-extras-java8time</artifactId>
|
||||||
|
<version>3.0.4.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package de.ph87.data.series;
|
package de.ph87.data.series;
|
||||||
|
|
||||||
|
import jakarta.annotation.Nullable;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -8,16 +9,40 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Controller
|
@Controller
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SeriesController {
|
public class SeriesController {
|
||||||
|
|
||||||
|
private final SeriesRepository seriesRepository;
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public String index(@NonNull final Model model) {
|
public String index(@NonNull final Model model) {
|
||||||
// model.addAttribute("series", getAll());
|
final Stream<Series> series = seriesRepository.findAll().stream().sorted(Comparator.comparing(Series::getName));
|
||||||
|
model.addAttribute("series", series);
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static String numberFormat(@Nullable final Double value, final int decimals) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return "%%.%df".formatted(decimals).formatted(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static String dateTimeFormat(@Nullable final ZonedDateTime date) {
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return date.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,50 @@
|
|||||||
<table>
|
<!DOCTYPE html>
|
||||||
<!-- <tr th:each="serie: ${series}">-->
|
<html lang="de">
|
||||||
<!-- <td th:text="${serie.name}"></td>-->
|
<head>
|
||||||
<!-- </tr>-->
|
<meta http-equiv="refresh" content="5">
|
||||||
</table>
|
<title>Data</title>
|
||||||
|
<style>
|
||||||
|
.section {
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
font-family: monospace;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th {
|
||||||
|
border: 2px solid white;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: lightgray;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value {
|
||||||
|
text-align: right;
|
||||||
|
border-right: none;
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unit {
|
||||||
|
border-left: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="section">
|
||||||
|
<table>
|
||||||
|
<tr th:each="serie: ${series}">
|
||||||
|
<td class="name" th:text="${serie.name}"></td>
|
||||||
|
<td class="mode" th:text="${serie.mode}"></td>
|
||||||
|
|
||||||
|
<td class="value" th:text="${@seriesController.numberFormat(serie.lastValue, 1)}"></td>
|
||||||
|
<td class="unit" th:text="${serie.unit}"></td>
|
||||||
|
|
||||||
|
<td class="date" th:text="${@seriesController.dateTimeFormat(serie.lastDate)}"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user