vrode work

This commit is contained in:
Katerina881 2023-03-06 15:00:42 +04:00
parent 095b718813
commit 15bc523a42
8 changed files with 127 additions and 37 deletions

41
frontend/index.html Normal file
View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
<title>Document</title>
</head>
<body>
<form class="" id="form">
<h2>Калькулятор</h2>
<div class="container row">
<div class="form-group col-3">
<label>num1</label>
<input name="num1" type="number" class="form-control col-3" placeholder="Первый аргумент">
</div>
<div class="form-group col-3">
<label>Оператор</label>
<select name="selected" id="inputState" class="form-control">
<option selected>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
</div>
<div class="form-group col-3">
<label>num2</label>
<input name="num2" type="number" class="form-control col-3" placeholder="Второй аргумент">
</div>
</div>
<button type="submit" class="btn btn-primary m-3">Посчитать</button>
</form>
<h2 class="text" id="res"></h2>
<script src="./node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="../js/script.js"></script>
</body>
</html>

39
frontend/js/script.js Normal file
View File

@ -0,0 +1,39 @@
let form = document.getElementById("form");
let info = document.getElementById("res");
form.onsubmit = async (e) => {
e.preventDefault();
if(form.num1.value === "") return;
if(form.num2.value === "") return;
let index = form.selected.selectedIndex;
let op = form.selected.options[index].textContent;
let res = "";
switch(op) {
case "+":
res = await fetch(`http://localhost:8080/sum?num1=${form.num1.value}&num2=${form.num2.value}`)
res = await res.text();
break;
case "-":
res = await fetch(`http://localhost:8080/diff?num1=${form.num1.value}&num2=${form.num2.value}`)
res = await res.text();
break;
case "*":
res = await fetch(`http://localhost:8080/multiply?num1=${form.num1.value}&num2=${form.num2.value}`)
res = await res.text();
break;
case "/":
if(form.num2.value == 0) return;
res = await fetch(`http://localhost:8080/divide?num1=${form.num1.value}&num2=${form.num2.value}`)
res = await res.text();
break;
}
info.textContent = res;
}

15
frontend/package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "frontend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "http-server -p 3000 -c-1 -o ./"
},
"author": "",
"license": "ISC",
"dependencies": {
"bootstrap": "^5.2.3",
"http-server": "^14.1.1"
}
}

View File

@ -14,25 +14,28 @@ public class SbappApplication {
SpringApplication.run(SbappApplication.class, args); SpringApplication.run(SbappApplication.class, args);
} }
@GetMapping("/hello") @GetMapping("/sum")
public String hello() { public Integer sum(@RequestParam Integer num1,
return "Hello, i'm working!"; @RequestParam Integer num2) {
}
@GetMapping("/ToUpper")
public String ToUpper(@RequestParam(value = "", defaultValue = "default") String text) {
return String.format(text).toUpperCase();
}
@GetMapping("/calc")
public Integer calc(@RequestParam(defaultValue = "10") Integer num1,
@RequestParam(defaultValue = "10") Integer num2) {
return num1 + num2; return num1 + num2;
} }
@GetMapping("/concate") @GetMapping("/diff")
public String concate(@RequestParam String text) { public Integer diff(@RequestParam Integer num1,
return "Word-"+ text; @RequestParam Integer num2) {
return num1 - num2;
}
@GetMapping("/multiply")
public Integer multiply(@RequestParam Integer num1,
@RequestParam Integer num2) {
return num1 * num2;
}
@GetMapping("/divide")
public Integer divide(@RequestParam Integer num1,
@RequestParam Integer num2) {
return num1 / num2;
} }
@GetMapping("/divider") @GetMapping("/divider")

View File

@ -0,0 +1,13 @@
package ru.ulstu.is.sbapp;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*");
}
}

View File

@ -1,3 +0,0 @@
h1 {
color: red;
}

View File

@ -1,7 +0,0 @@
function test() {
fetch("http://localhost:8080/hello", {
mode:
}
}
test();

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html xmlns:th = "http://www.thymeleaf.org">
<head>
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<h1> IA WORK!</h1>
</body>
</html>