Commit cbbebbea by Patryk Czarnik

Kalkulator - pierwsza wersja

parent 56e57b9f
package com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/kalkulator")
public class KalkulatorController {
@GetMapping
public String kalkulatorGet() {
return "kalkulator.html";
}
@PostMapping
public String kalkulatorPost(Long liczba1, Long liczba2, Model model) {
model.addAttribute("wynik", liczba1+liczba2);
return "kalkulator.html";
}
}
<!DOCTYPE html>
<html lang="pl" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Rozmowa</title>
<link rel="stylesheet" type="text/css" th:href="@{/styl.css}" href="../static/styl.css">
</head>
<body>
<h1>Rozmowa ze Springiem</h1>
<form method="post">
<label for="liczba1">Podaj pierwszą liczbę</label><br>
<input type="text" name="liczba1" id="liczba1"><br>
<label for="liczba2">Podaj drugą liczbę</label><br>
<input type="text" name="liczba2" id="liczba2"><br>
<button>Dodaj</button>
</form>
<div class="wynik"
th:if="${wynik != null}"
th:text="${wynik}">1234</div>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment