-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathFirstController.java
More file actions
48 lines (40 loc) · 1.42 KB
/
FirstController.java
File metadata and controls
48 lines (40 loc) · 1.42 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
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="a", required = false) int a,
@RequestParam(value="b", required = false) int b,
@RequestParam(value="action", required = false) String action,
Model model) {
model.addAttribute("someMessage","result "+ a + action + b +" = " + calculate(a,b,action));
//int sum = calculate(a,b,action);
//System.out.println("Hello, " + name + " " + surname);
return "first/hello";
}
public int calculate(int a, int b, String action) {
switch (action) {
case "multiplication":
return a * b;
case "addition":
return a+b;
case "substruction":
return a%b;
case "division":
return a-b;
default: return 0;
}
}
@GetMapping("/goodbye")
public String goodByePage() {
return "first/goodbye";
}
}