forked from NeilAlishev/SpringCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstController.java
More file actions
60 lines (49 loc) · 1.68 KB
/
FirstController.java
File metadata and controls
60 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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";
}
}