#18- Add controller
This commit is contained in:
parent
caae6eae5a
commit
fc2f0c209a
@ -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";
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
|
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
|
||||||
<html
|
<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}">
|
layout:decorate="~{default}">
|
||||||
<head>
|
<head>
|
||||||
<title>Простая обработка формы на Spring MVC</title>
|
<title>Простая обработка формы на Spring MVC</title>
|
||||||
@ -8,18 +8,27 @@
|
|||||||
</head>
|
</head>
|
||||||
<div class="container" layout:fragment="content">
|
<div class="container" layout:fragment="content">
|
||||||
<script src="https://www.google.com/jsapi"></script>
|
<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.load("visualization", "1", {packages: ["corechart"]});
|
||||||
google.setOnLoadCallback(drawChart);
|
google.setOnLoadCallback(drawChart);
|
||||||
|
|
||||||
function drawChart() {
|
function drawChart() {
|
||||||
var data = google.visualization.arrayToDataTable([
|
|
||||||
['Газ', 'Объём'],
|
var arr = [[${data}]];
|
||||||
['Азот', 78.09],
|
var data = google.visualization.arrayToDataTable(arr);
|
||||||
['Кислород', 20.95],
|
|
||||||
['Аргон', 0.93],
|
|
||||||
['Углекислый газ', 0.03]
|
|
||||||
]);
|
|
||||||
var options = {
|
var options = {
|
||||||
title: 'Состав воздуха',
|
title: 'Состав воздуха',
|
||||||
is3D: true,
|
is3D: true,
|
||||||
@ -51,5 +60,7 @@
|
|||||||
</script>
|
</script>
|
||||||
<div id="air" style="width: 500px; height: 400px;"></div>
|
<div id="air" style="width: 500px; height: 400px;"></div>
|
||||||
<div id="oil" 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>
|
</div>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user