Compare commits

...

1 Commits

Author SHA1 Message Date
7fa4777711 врварвава 2023-03-04 15:27:44 +03:00
3 changed files with 47 additions and 20 deletions

View File

@ -2,34 +2,30 @@ function setResult(result) {
let lbl = `<label class="bg-success">Ответ:${result}</label>`; let lbl = `<label class="bg-success">Ответ:${result}</label>`;
document.getElementById("result").innerHTML = 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(){ function add(){
address = "add" executeRequest("add");
executeRequest();
} }
function sub(){ function sub(){
address = "sub" executeRequest("sub");
executeRequest();
} }
function mul(){ function mul(){
address = "mul" executeRequest("mul");
executeRequest();
} }
function del(){ function del(){
executeRequest("del");
address = "del"
if(b.value != 0) executeRequest();
} }
function executeRequest() { function enterArray(){
executeRequestArray("array");
}
let num1 = a.value; function executeRequest(address) {
let num2 = b.value; let num1 = document.getElementById("addNum1").value;
let num2 = document.getElementById("addNum2").value;
console.log("a" + num1 + "b" + num2) console.log("a" + num1 + "b" + num2)
fetch(`http://localhost:8080/${address}?a=${num1}&b=${num2}`) fetch(`http://localhost:8080/${address}?a=${num1}&b=${num2}`)
.then(response => { .then(response => {
@ -39,3 +35,14 @@ function executeRequest() {
setResult(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);
})
}

View File

@ -18,8 +18,12 @@
<button class="btn btn-success" onclick="sub()">Вычесть</button> <button class="btn btn-success" onclick="sub()">Вычесть</button>
<button class="btn btn-success" onclick="mul()">Умножить</button> <button class="btn btn-success" onclick="mul()">Умножить</button>
<button class="btn btn-success" onclick="del()">Поделить</button> <button class="btn btn-success" onclick="del()">Поделить</button>
<input type="text" class="form-control" id="enterArray" placeholder="" value="0" required="" style="width: 10%;">
<button class="btn btn-success" onclick="enterArray()">Ввести</button>
<div id="result">Ответ:</div> <div id="result">Ответ:</div>
<br>
<br>

View File

@ -38,12 +38,28 @@ public class MyappApplication {
@GetMapping("/del") @GetMapping("/del")
public Integer doDel(@RequestParam(value = "a", defaultValue = "0") int a, public Integer doDel(@RequestParam(value = "a", defaultValue = "0") int a,
@RequestParam(value = "b", defaultValue = "1") int b){ @RequestParam(value = "b", defaultValue = "1") int b){
if(b!=0) {
return a / b; return a / b;
} }
return null;
}
@GetMapping("/mu") @GetMapping("/mu")
public String len(@RequestParam(value = "word", defaultValue = "") String name){ public String len(@RequestParam(value = "word", defaultValue = "") String name){
return String.format("Длина слова " + name + " " + len(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") @GetMapping("/de")
public String root(){ public String root(){
return new Date().toString(); return new Date().toString();