Controller(calc)

This commit is contained in:
AnnZhimol 2023-02-06 14:41:17 +04:00
parent cc3d434da6
commit 815967146e

View File

@ -2,12 +2,32 @@ package ru.ulstu.is.cbapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class CbappApplication {
public static void main(String[] args) {
SpringApplication.run(CbappApplication.class, args);
}
@GetMapping("/calc")
public Integer doSum(@RequestParam(defaultValue = "10") int val1,
@RequestParam(defaultValue = "2") int val2,
@RequestParam(defaultValue = "+") String value) {
switch(value){
case "-":
return val1-val2;
case "*":
return val1*val2;
case "/":
return val1/val2;
default:
return val1+val2;
}
}
}