vrode work
This commit is contained in:
parent
095b718813
commit
15bc523a42
41
frontend/index.html
Normal file
41
frontend/index.html
Normal 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
39
frontend/js/script.js
Normal 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
15
frontend/package.json
Normal 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"
|
||||
}
|
||||
}
|
@ -14,25 +14,28 @@ public class SbappApplication {
|
||||
SpringApplication.run(SbappApplication.class, args);
|
||||
}
|
||||
|
||||
@GetMapping("/hello")
|
||||
public String hello() {
|
||||
return "Hello, i'm working!";
|
||||
}
|
||||
|
||||
@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) {
|
||||
@GetMapping("/sum")
|
||||
public Integer sum(@RequestParam Integer num1,
|
||||
@RequestParam Integer num2) {
|
||||
return num1 + num2;
|
||||
}
|
||||
|
||||
@GetMapping("/concate")
|
||||
public String concate(@RequestParam String text) {
|
||||
return "Word-"+ text;
|
||||
@GetMapping("/diff")
|
||||
public Integer diff(@RequestParam Integer num1,
|
||||
@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")
|
||||
|
13
src/main/java/ru/ulstu/is/sbapp/WebConfiguration.java
Normal file
13
src/main/java/ru/ulstu/is/sbapp/WebConfiguration.java
Normal 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("*");
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
h1 {
|
||||
color: red;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
function test() {
|
||||
fetch("http://localhost:8080/hello", {
|
||||
mode:
|
||||
}
|
||||
}
|
||||
|
||||
test();
|
@ -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>
|
Loading…
Reference in New Issue
Block a user