diff --git a/front/MyScript.js b/front/MyScript.js index 7907977..ffab0cb 100644 --- a/front/MyScript.js +++ b/front/MyScript.js @@ -2,34 +2,30 @@ function setResult(result) { let lbl = ``; document.getElementById("result").innerHTML = lbl; } -let addButton = document.getElementById("getResultAdd"); -let a = document.getElementById("addNum1"); -let b = document.getElementById("addNum2"); -let Output = document.getElementById("addAnswer"); -let address = "hello" + function add(){ -address = "add" -executeRequest(); + executeRequest("add"); } + function sub(){ -address = "sub" -executeRequest(); + executeRequest("sub"); } + function mul(){ -address = "mul" -executeRequest(); + executeRequest("mul"); } + function del(){ - -address = "del" -if(b.value != 0) executeRequest(); - + executeRequest("del"); } -function executeRequest() { +function enterArray(){ + executeRequestArray("array"); +} - let num1 = a.value; - let num2 = b.value; +function executeRequest(address) { + let num1 = document.getElementById("addNum1").value; + let num2 = document.getElementById("addNum2").value; console.log("a" + num1 + "b" + num2) fetch(`http://localhost:8080/${address}?a=${num1}&b=${num2}`) .then(response => { @@ -38,4 +34,15 @@ function executeRequest() { .then(result => { setResult(result); }) +} + +function executeRequestArray(address) { + let array = document.getElementById("enterArray").value; + fetch(`http://localhost:8080/${address}?InputNumbers=${array}`) + .then(response => { + return response.json(); + }) + .then(result => { + setResult(result); + }) } \ No newline at end of file diff --git a/front/index.html b/front/index.html index 5247738..64e7a97 100644 --- a/front/index.html +++ b/front/index.html @@ -18,8 +18,12 @@ - + +
Ответ:
+
+
+ diff --git a/src/main/java/ru/ulstu/is/myapp/MyappApplication.java b/src/main/java/ru/ulstu/is/myapp/MyappApplication.java index 1b6c49a..22da60b 100644 --- a/src/main/java/ru/ulstu/is/myapp/MyappApplication.java +++ b/src/main/java/ru/ulstu/is/myapp/MyappApplication.java @@ -38,12 +38,28 @@ public class MyappApplication { @GetMapping("/del") public Integer doDel(@RequestParam(value = "a", defaultValue = "0") int a, @RequestParam(value = "b", defaultValue = "1") int b){ - return a / b; + if(b!=0) { + return a / b; + } + return null; } @GetMapping("/mu") public String len(@RequestParam(value = "word", defaultValue = "") String name){ return String.format("Длина слова " + name + " " + len(name)); } + @CrossOrigin + @GetMapping("/array") + public Integer[] massive(@RequestParam(value = "InputNumbers") Integer[] inputNumbers){ + + + + String str = ""; + + for(int i = 0; i < inputNumbers.length; i++){ + inputNumbers[i] = (inputNumbers[i] + 1); + } + return inputNumbers; + } @GetMapping("/de") public String root(){ return new Date().toString();