Первая лабораторная работа.
This commit is contained in:
parent
5e05dd5f2a
commit
62ec7e0fb4
@ -2,6 +2,8 @@ package com.example.ipLab;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class IpLabApplication {
|
public class IpLabApplication {
|
||||||
@ -9,5 +11,4 @@ public class IpLabApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(IpLabApplication.class, args);
|
SpringApplication.run(IpLabApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.example.ipLab;
|
||||||
|
|
||||||
|
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("*");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.example.ipLab.controllers;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class CalcController {
|
||||||
|
|
||||||
|
@GetMapping("/second")
|
||||||
|
public int second(@RequestParam(value = "num") int num){
|
||||||
|
return num*num;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/root")
|
||||||
|
public double root(@RequestParam(value = "num") int num){
|
||||||
|
return Math.sqrt(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/fact")
|
||||||
|
public int fact(@RequestParam(value = "num") int num){
|
||||||
|
int res = 1;
|
||||||
|
for (int i = 2; i <= num; i++) {
|
||||||
|
res *= i;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/digit")
|
||||||
|
public int digit(@RequestParam(value = "num") int num){
|
||||||
|
if (num < 0) num *= -1;
|
||||||
|
int sum = 0;
|
||||||
|
while (num > 0) {
|
||||||
|
sum += num % 10;
|
||||||
|
num /= 10;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
}
|
25
frontend/index.html
Normal file
25
frontend/index.html
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru" class="h-100">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<script src ="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||||
|
<script src ="scripts/calc.js"></script>
|
||||||
|
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
|
||||||
|
<link href="node_modules/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet" />
|
||||||
|
<title>Calc</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
|
</head>
|
||||||
|
<body class="h-100">
|
||||||
|
<div class="d-flex flex-column align-content-center flex-wrap">
|
||||||
|
<div class="input-group p-3">
|
||||||
|
<input id="numberInput" type="number" class="form-control" placeholder="Введите число..." required>
|
||||||
|
<button class="btn btn-outline-secondary" onclick="calcSecond()" type="button">^2</button>
|
||||||
|
<button class="btn btn-outline-secondary" onclick="calcRoot()" type="button">√</button>
|
||||||
|
<button class="btn btn-outline-secondary" onclick="calcFact()" type="button">!</button>
|
||||||
|
<button class="btn btn-outline-secondary" onclick="calcDigit()" type="button">Сумма цифр</button>
|
||||||
|
</div>
|
||||||
|
<a id="responseField" class="m-3"></a>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
19
frontend/package.json
Normal file
19
frontend/package.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "ip_lab",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "My project for IP lab",
|
||||||
|
"main": "index.html",
|
||||||
|
"scripts": {
|
||||||
|
"start": "http-server -p 3000 ./",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "Abazov Andrey",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"bootstrap": "5.2.1",
|
||||||
|
"@fortawesome/fontawesome-free": "6.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"http-server": "14.1.1"
|
||||||
|
}
|
||||||
|
}
|
70
frontend/scripts/calc.js
Normal file
70
frontend/scripts/calc.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
function calcSecond(){
|
||||||
|
var num = document.getElementById("numberInput").value;
|
||||||
|
fetch("http://127.0.0.1:8080/second?num=" + num)
|
||||||
|
.then(function(response) {
|
||||||
|
if (response.status != 200){
|
||||||
|
return response.text().then(text => {throw new Error(text)});
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
document.getElementById("responseField").innerHTML = "Результат: " + response;
|
||||||
|
})
|
||||||
|
.catch(err => {document.getElementById("responseField").innerHTML = "Ошибка: " + err;})
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcRoot(){
|
||||||
|
var num = document.getElementById("numberInput").value;
|
||||||
|
if (num < 0) {
|
||||||
|
document.getElementById("responseField").innerHTML = "Результат: введите НЕОТРИЦАТЕЛЬНОЕ число";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetch("http://127.0.0.1:8080/root?num=" + num)
|
||||||
|
.then((response) => {
|
||||||
|
if (response.status != 200){
|
||||||
|
return response.text().then(text => {throw new Error(text)});
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response);
|
||||||
|
document.getElementById("responseField").innerHTML = "Результат: " + response;
|
||||||
|
})
|
||||||
|
.catch(err => {document.getElementById("responseField").innerHTML = "Ошибка: " + err;})
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcFact(){
|
||||||
|
var num = document.getElementById("numberInput").value;
|
||||||
|
if (num < 0) {
|
||||||
|
document.getElementById("responseField").innerHTML = "Результат: введите НЕОТРИЦАТЕЛЬНОЕ число";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetch("http://127.0.0.1:8080/fact?num=" + num)
|
||||||
|
.then((response) => {
|
||||||
|
if (response.status != 200){
|
||||||
|
return response.text().then(text => {throw new Error(text)});
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response);
|
||||||
|
document.getElementById("responseField").innerHTML = "Результат: " + response;
|
||||||
|
})
|
||||||
|
.catch(err => {document.getElementById("responseField").innerHTML = "Ошибка: " + err;})
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcDigit(){
|
||||||
|
var num = document.getElementById("numberInput").value;
|
||||||
|
fetch("http://127.0.0.1:8080/digit?num=" + num)
|
||||||
|
.then((response) => {
|
||||||
|
if (response.status != 200){
|
||||||
|
return response.text().then(text => {throw new Error(text)});
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response);
|
||||||
|
document.getElementById("responseField").innerHTML = "Результат: " + response;
|
||||||
|
})
|
||||||
|
.catch(err => {document.getElementById("responseField").innerHTML = "Ошибка: " + err;})
|
||||||
|
}
|
6
frontend/style.css
Normal file
6
frontend/style.css
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#responseField{
|
||||||
|
font-family: Segoe UI;
|
||||||
|
font-size: 24px;
|
||||||
|
color: black;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user