/
Hipahopa808
/
SpringCourse
Обзор
Документация
Войти
/
Hipahopa808
/
SpringCourse
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Lesson20.IntroToModel/src/main/java/ru/alishev/springcourse/controllers/FirstController.java
60 строк
2 KB
Neil Alishev
Add Lesson 20 code
04 июл 2020, 15:49
04 июл 2020, 15:49
74b182e
Код
Авторство
О чём код?
package ru.alishev.springcourse.controllers; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; /** * @author Neil Alishev */ @Controller @RequestMapping("/first") public class FirstController { @GetMapping("/hello") public String helloPage(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "surname", required = false) String surname, Model model) { // System.out.println("Hello, " + name + " " + surname); model.addAttribute("message", "Hello, " + name + " " + surname); return "first/hello"; } @GetMapping("/goodbye") public String goodByePage() { return "first/goodbye"; } @GetMapping("/calculator") public String calculator(@RequestParam("a") int a, @RequestParam("b") int b, @RequestParam("action") String action, Model model) { double result; switch (action) { case "multiplication": result = a * b; break; case "division": result = a / (double) b; break; case "subtraction": result = a - b; break; case "addition": result = a + b; break; default: result = 0; break; } model.addAttribute("result", result); return "first/calculator"; } }