врварвава

This commit is contained in:
dimazhelovanov 2023-03-04 15:27:44 +03:00
parent 1c461b1134
commit 7fa4777711
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>`;
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 => {
@ -39,3 +35,14 @@ function executeRequest() {
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="mul()">Умножить</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>
<br>
<br>

View File

@ -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();