Commit 856db191 by Patryk Czarnik

kalkulator - pierwsza wersja

parent 0d990c00
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 rozmowaGet() {
return "kalkulator.html";
}
@PostMapping
public String rozmowaPost(Integer liczba1, Integer liczba2, String operacja, Model model) {
Integer wynik = liczba1 + liczba2;
model.addAttribute("wynik", wynik);
return "kalkulator.html";
}
}
<!DOCTYPE html>
<html lang="pl" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Kalkulator</title>
<link rel="stylesheet" type="text/css" th:href="@{/styl.css}" href="../static/styl.css">
</head>
<body>
<h1>Kalkulator</h1>
<form method="post">
<p>Wprowadź liczby i wybierz działanie</p>
<input type="number" name="liczba1" id="liczba1" th:value="${param.liczba1}">
<select name="operacja">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="number" name="liczba2" id="liczba2" th:value="${param.liczba2}">
<button>Oblicz</button>
</form>
<div class="wynik">
[[${wynik}]]
</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