This commit is contained in:
Екатерина Рогашова 2023-03-14 10:00:36 +04:00
parent e4d075f7f9
commit 6ffff5b55b
9 changed files with 303 additions and 1 deletions

71
Front/index.html Normal file
View File

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>App</title>
<script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container-sm p-3">
Выберите тип данных
<div>
<select id="type" class="form-select" >
<option value="int">Число</option>
<option value="string">Строка</option>
</select>
</div>
<form id="ToUpperCase">
<h2 class="text-center mb-3">To Upper</h2>
<div class="mb-3">
<div class="input-group mb-1">
<input type="text" id="input1" class="form-control" placeholder="Введите строчку" aria-label="Your String" name="value" autocomplete="off">
<button type="button" class="btn btn-primary" id="btn_tuc" onclick="TUC()">Применить</button>
</div>
<input type="text" class="form-control result" id="tuc_result" readonly>
</div>
</form>
<form id="toLowerCase">
<h2 class="text-center mb-3">To Lower</h2>
<div class="mb-3">
<div class="input-group mb-1">
<input type="text" id="input2" class="form-control" placeholder="Введите строчку" aria-label="Your String" name="value" autocomplete="off">
<button type="button" class="btn btn-primary" id="btn_tlc" onclick="TLC()">Применить</button>
</div>
<input type="text" class="form-control result" id="tlc_result" readonly>
</div>
</form>
<form id="charAt">
<h2 class="text-center mb-3">Sum</h2>
<div class="mb-3">
<div class="input-group mb-1">
<input type="text" id="input3" class="form-control" placeholder="Введите строчку" aria-label="Your String" name="value" autocomplete="off">
<input type="text" id="input4" class="form-control" placeholder="Введите строчку" aria-label="Your String" name="value" autocomplete="off">
<button type="button" class="btn btn-primary" onclick="CHAR()"id="btn_chAt">Применить</button>
</div>
<input type="text" class="form-control result" id="chAt_result" readonly>
</div>
</form>
<form id="substring">
<h2 class="text-center mb-3">Sum /2</h2>
<div class="mb-3">
<div class="input-group mb-1">
<input type="text" id="input5" class="form-control" placeholder="Введите строчку" aria-label="Your String" name="value" autocomplete="off">
<input type="text" id="input6" class="form-control" placeholder="Введите строчку" aria-label="Your String" name="value" autocomplete="off">
<button type="button" class="btn btn-primary" onclick="SUB()"id="btn_sub">Применить </button>
</div>
<input type="text" class="form-control result" id="sub_result" readonly>
</div>
</form>
</div>
<script src="index.js"></script>
</body>
</html>

48
Front/index.js Normal file
View File

@ -0,0 +1,48 @@
'use strict'
let num1 = document.getElementById("input1")
let num2 = document.getElementById("input2")
let num3 = document.getElementById("input3")
let num4 = document.getElementById("input4")
let num5 = document.getElementById("input5")
let num6 = document.getElementById("input6")
let tucrez = document.getElementById("tuc_result")
let tlcrez = document.getElementById("tlc_result")
let chAtrez = document.getElementById("chAt_result")
let subrez = document.getElementById("sub_result")
let typeInput = document.getElementById("type");
function TUC(){
let val1 = num1.value
let type = typeInput.value;
fetch(`http://localhost:8080/toUpperCase/${val1}`)
.then(response => response.text())
.then(data =>{tucrez.value=data});
}
function TLC(){
let val1 = num2.value
let type = typeInput.value;
fetch(`http://localhost:8080/toLowerCase/${val1}`)
.then(response => response.text())
.then(data =>{tlcrez.value=data});
}
function CHAR(){
let val1 = num3.value
let val2 = num4.value
let type = typeInput.value;
fetch(`http://localhost:8080/charAt/${val1}/${val2}`)
.then(response => response.text())
.then(data =>{chAtrez.value=data});
}
function SUB(){
let val1 = num5.value
let val2 = num6.value
let type = typeInput.value;
fetch(`http://localhost:8080/substring/${val1}/${val2}`)
.then(response => response.text())
.then(data =>{subrez.value=data});
}

View File

@ -0,0 +1,41 @@
package ru.ulstu.is.sbapp;
import ru.ulstu.is.sbapp.MethodService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Controllers {
private final MethodService speakerService;
public Controllers(MethodService speakerService) {
this.speakerService = speakerService;
}
@GetMapping("/toUpper")
public String toUpper(@RequestParam(value = "first", defaultValue = "1") Object first,
@RequestParam(value = "type", defaultValue = "int") String type) {
return speakerService.toUpper(first, type);
}
@GetMapping("/toLower")
public String toLower(@RequestParam(value = "first", defaultValue = "1") Object first,
@RequestParam(value = "type", defaultValue = "int") String type) {
return speakerService.toLower(first, type);
}
@GetMapping("/sum")
public String sum(@RequestParam(value = "first", defaultValue = "1") Object first,
@RequestParam(value = "second", defaultValue = "1") Object second,
@RequestParam(value = "type", defaultValue = "int") String type) {
return speakerService.sum(first, second, type);
}
@GetMapping("/sum1")
public String sum1(@RequestParam(value = "first", defaultValue = "1") Object first,
@RequestParam(value = "second", defaultValue = "1") Object second,
@RequestParam(value = "type", defaultValue = "int") String type) {
return speakerService.sum1(first, second, type);
}
}

View File

@ -0,0 +1,8 @@
package ru.ulstu.is.sbapp.Interfaces;
public interface ITypeInterface<T> {
T Method1(T value1);
T Method2(T value1);
T Method3(T value1, T value2);
T Method4(T value1, T value2);
}

View File

@ -0,0 +1,23 @@
package ru.ulstu.is.sbapp.Interfaces;
public class IntegerType implements ITypeInterface<Integer> {
@Override
public Integer Method1(Integer value1) {
return value1 + value1;
}
@Override
public Integer Method2(Integer value1) {
return value1 - value1/2;
}
@Override
public Integer Method3(Integer value1, Integer value2) {
return value1 + value2;
}
@Override
public Integer Method4(Integer value1, Integer value2) {
return value1/2 + value2/2;
}
}

View File

@ -0,0 +1,24 @@
package ru.ulstu.is.sbapp.Interfaces;
public class StringType implements ITypeInterface<String> {
@Override
public String Method1(String value1) {
return value1.toUpperCase();
}
@Override
public String Method2(String value1) {
return value1.toLowerCase();
}
@Override
public String Method3(String value1, String value2) {
return value1.toLowerCase() + value2.toLowerCase();
}
@Override
public String Method4(String value1, String value2) {
return value1.toUpperCase() + value2.toUpperCase();
}
}

View File

@ -0,0 +1,52 @@
package ru.ulstu.is.sbapp;
import ru.ulstu.is.sbapp.Interfaces.ITypeInterface;
import ru.ulstu.is.sbapp.Interfaces.StringType;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
@Service
public class MethodService {
private final ApplicationContext applicationContext;
public MethodService(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
public String toUpper(Object first, String type) {
final ITypeInterface speaker = (ITypeInterface) applicationContext.getBean(type);
if (speaker instanceof StringType){
return String.format("%s", speaker.Method1(first));
}else{
return String.format("%s", speaker.Method1(Integer.parseInt(first.toString())));
}
}
public String toLower(Object first, String type) {
final ITypeInterface speaker = (ITypeInterface) applicationContext.getBean(type);
if (speaker instanceof StringType){
return String.format("%s", speaker.Method2(first));
}else{
return String.format("%s", speaker.Method2(Integer.parseInt(first.toString())));
}
}
public String sum(Object first, Object second, String type) {
final ITypeInterface speaker = (ITypeInterface) applicationContext.getBean(type);
if (speaker instanceof StringType){
return String.format("%s", speaker.Method3(first,second));
}else{
return String.format("%s", speaker.Method3(Integer.parseInt(first.toString()),Integer.parseInt(second.toString())));
}
}
public String sum1(Object first, Object second, String type) {
final ITypeInterface speaker = (ITypeInterface) applicationContext.getBean(type);
if (speaker instanceof StringType){
return String.format("%s", speaker.Method4(first,second));
}else {
return String.format("%s", speaker.Method4(Integer.parseInt(first.toString()), Integer.parseInt(second.toString())));
}
}
}

View File

@ -2,12 +2,33 @@ package ru.ulstu.is.sbapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;
@SpringBootApplication
@RestController
@CrossOrigin
public class SbappApplication {
public static void main(String[] args) {
SpringApplication.run(SbappApplication.class, args);
}
@GetMapping("/toUpperCase/{value}")
public @ResponseBody String toUpperCase(@PathVariable String value) {
return value.toUpperCase();
}
@GetMapping("/toLowerCase/{value}")
public @ResponseBody String toLowerCase(@PathVariable String value) {
return value.toLowerCase();
}
@GetMapping("/charAt/{v1}/{v2}")
public Character charAt(@PathVariable String v1, @PathVariable Integer v2) {
Character c = v1.charAt(v2-1);
return c;
}
@GetMapping("/substring/{v1}/{v2}")
public String substring(@PathVariable String v1, @PathVariable Integer v2) {
String str = v1.substring(v2);
return str;
}
}

View File

@ -0,0 +1,14 @@
package ru.ulstu.is.sbapp;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
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("*");
}
}