#18- Add controller

This commit is contained in:
BarminaA 2021-04-02 14:12:05 +04:00
parent caae6eae5a
commit fc2f0c209a
2 changed files with 55 additions and 9 deletions

View File

@ -0,0 +1,35 @@
package ru.ulstu.extractor.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.extractor.repository.BranchRepository;
import ru.ulstu.extractor.repository.RepositoryRepository;
@Controller
public class StatisticController {
private final RepositoryRepository repositoryRepository;
private final BranchRepository branchRepository;
public StatisticController(RepositoryRepository repositoryRepository, BranchRepository branchRepository) {
this.repositoryRepository = repositoryRepository;
this.branchRepository = branchRepository;
}
@GetMapping("/statistic")
public String indexBranch(
Model model) {
String[] continents = {
"Africa", "Antarctica", "Asia", "Australia",
"Europe", "North America", "Sourth America"
};
model.addAttribute("continents", continents);
model.addAttribute("array", new int[]{1,2,3});
String[][] data = new String[][] {{"Газ", "Объём"}, {"Dsdfsdf", "10"}};
model.addAttribute("data", data);
return "statistic";
}
}

View File

@ -1,6 +1,6 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
@ -8,18 +8,27 @@
</head>
<div class="container" layout:fragment="content">
<script src="https://www.google.com/jsapi"></script>
<script>
<script type="text/javascript" >
var items = [];
/*[# th:each="n : ${items}"]*/
items.push("[(${n})]");
/*[/]*/
console.log(items);
</script>
<script th:inline="javascript">
var username = [[${array}]];
console.log(username);
</script>
<script th:inline="javascript">
google.load("visualization", "1", {packages: ["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Газ', 'Объём'],
['Азот', 78.09],
['Кислород', 20.95],
['Аргон', 0.93],
['Углекислый газ', 0.03]
]);
var arr = [[${data}]];
var data = google.visualization.arrayToDataTable(arr);
var options = {
title: 'Состав воздуха',
is3D: true,
@ -51,5 +60,7 @@
</script>
<div id="air" style="width: 500px; height: 400px;"></div>
<div id="oil" style="width: 500px; height: 400px;"></div>
<ul th:each="continet : ${continents}"></ul>
<h4 th:each="continent : ${continents}" th:text="${continent}"></h4>
</div>
</html>