Compare commits
No commits in common. "LabWork1" and "main" have entirely different histories.
67
index.html
67
index.html
@ -1,67 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru-ru">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Vite App</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container-sm p-3">
|
|
||||||
<form id="plus">
|
|
||||||
<h2 class="text-center mb-3">Plus</h2>
|
|
||||||
<div class="mb-3">
|
|
||||||
<div class="input-group mb-1">
|
|
||||||
<input id="value1plus" type="number" class="form-control" placeholder="V1" aria-label="First Number" name="v1" autocomplete="off">
|
|
||||||
<span class="input-group-text">+</span>
|
|
||||||
<input id ="value2plus" type="number" class="form-control" placeholder="V2" aria-label="Second Number" name="v2" autocomplete="off">
|
|
||||||
<span class="input-group-text" id="plus_result">0</span>
|
|
||||||
<button id = "buttonplus" type="submit" class="btn btn-primary">Submit</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="minus">
|
|
||||||
<h2 class="text-center mb-3">Minus</h2>
|
|
||||||
<div class="mb-3">
|
|
||||||
<div class="input-group mb-1">
|
|
||||||
<input id = "value1minus" type="number" class="form-control" placeholder="V1" aria-label="First Number" name="v1" autocomplete="off">
|
|
||||||
<span class="input-group-text">-</span>
|
|
||||||
<input id = "value2minus" type="number" class="form-control" placeholder="V2" aria-label="Second Number" name="v2" autocomplete="off">
|
|
||||||
<span class="input-group-text" id="minus_result">0</span>
|
|
||||||
<button id = "buttonminus" type="submit" class="btn btn-primary">Submit</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="mult">
|
|
||||||
<h2 class="text-center mb-3">Mult</h2>
|
|
||||||
<div class="mb-3">
|
|
||||||
<div class="input-group mb-1">
|
|
||||||
<input id = "value1mult" type="number" class="form-control" placeholder="V1" aria-label="First Number" name="v1" autocomplete="off">
|
|
||||||
<span class="input-group-text">*</span>
|
|
||||||
<input id = "value2mult" type="number" class="form-control" placeholder="V2" aria-label="Second Number" name="v2" autocomplete="off">
|
|
||||||
<span class="input-group-text" id="mult_result">0</span>
|
|
||||||
<button id = "buttonmult" type="submit" class="btn btn-primary">Submit</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="div">
|
|
||||||
<h2 class="text-center mb-3">Del</h2>
|
|
||||||
<div class="mb-3">
|
|
||||||
<div class="input-group mb-1">
|
|
||||||
<input id="value1div" type="number" class="form-control" placeholder="V1" aria-label="First Number" name="v1" autocomplete="off">
|
|
||||||
<span class="input-group-text">/</span>
|
|
||||||
<input id = "value2div" type="number" class="form-control" placeholder="V2" aria-label="Second Number" name="v2" autocomplete="off">
|
|
||||||
<span class="input-group-text" id="div_result">0</span>
|
|
||||||
<button id = "buttondiv" type="submit" class="btn btn-primary">Submit</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script type="module" src="main.js"></script>
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
|
||||||
</body>
|
|
||||||
</html>
|
|
27
main.js
27
main.js
@ -1,27 +0,0 @@
|
|||||||
const xhr = new XMLHttpRequest ()
|
|
||||||
|
|
||||||
const get = (operation, value1, value2) =>{
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
xhr.open('GET', `http://localhost:8080/${operation}?val1=${value1}&val2=${value2}`)
|
|
||||||
|
|
||||||
xhr.onload = () => {
|
|
||||||
if(xhr.status == 200) resolve(xhr.response)
|
|
||||||
else reject(xhr.response)
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.send()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelectorAll("form").forEach((item) => {
|
|
||||||
item.onsubmit = async (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
const form = e.target;
|
|
||||||
const val1 = form.v1.value;
|
|
||||||
const val2 = form.v2.value;
|
|
||||||
|
|
||||||
const responce = await get(form.id, val1, val2);
|
|
||||||
document.getElementById(`${form.id}_result`).innerHTML = responce;
|
|
||||||
}
|
|
||||||
})
|
|
@ -1,35 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
package com.example.demo.Controller;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@CrossOrigin
|
|
||||||
public class Controllers {
|
|
||||||
@GetMapping("/plus")
|
|
||||||
public @ResponseBody Integer Plus (@RequestParam (required = false, defaultValue = "0") int val1,
|
|
||||||
@RequestParam (required = false, defaultValue = "0") int val2){
|
|
||||||
return val1 + val2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/minus")
|
|
||||||
public @ResponseBody Integer Minus (@RequestParam (required = false, defaultValue = "0") int val1,
|
|
||||||
@RequestParam (required = false, defaultValue = "0") int val2){
|
|
||||||
return val1 - val2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/mult")
|
|
||||||
public @ResponseBody Integer Mult (@RequestParam (required = false, defaultValue = "0") int val1,
|
|
||||||
@RequestParam (required = false, defaultValue = "0") int val2){
|
|
||||||
return val1 * val2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/div")
|
|
||||||
public @ResponseBody Integer Div (@RequestParam (required = false, defaultValue = "0") int val1,
|
|
||||||
@RequestParam (required = false, defaultValue = "1") int val2){
|
|
||||||
return val1 / val2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
17
src/main/java/com/example/demo/Controller/Main.java
Normal file
17
src/main/java/com/example/demo/Controller/Main.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.example.demo.Controller;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public String helloWorld(@RequestParam(name = "name", required = false, defaultValue = "World") String name, Model model){
|
||||||
|
model.addAttribute( "name", name);
|
||||||
|
return "hello-world!";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user