From 04f358067ffe7096967c5b00f9d831c995aefd65 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sun, 19 Feb 2023 23:51:57 +0400 Subject: [PATCH] done --- .../labworks/controller/UserController.java | 14 +++++++------- .../frontend/spa-vue/src/pages/Index.vue | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ip/labworks/labworks/controller/UserController.java b/src/main/java/ru/ip/labworks/labworks/controller/UserController.java index 6517153..3efb036 100644 --- a/src/main/java/ru/ip/labworks/labworks/controller/UserController.java +++ b/src/main/java/ru/ip/labworks/labworks/controller/UserController.java @@ -10,17 +10,17 @@ import javax.servlet.http.HttpServletResponse; @RestController public class UserController { - @GetMapping("/sum") - public String workSum(HttpServletResponse response, @RequestParam Integer num1, @RequestParam Integer num2){ + @GetMapping("/sub") + public String workSub(HttpServletResponse response, @RequestParam String str1, @RequestParam String str2){ response.addHeader("Access-Control-Allow-Origin", "*"); - return String.format("Result = %s", num1 + num2); + return str1.substring(Integer.parseInt(str2)); } @GetMapping("/split") public String workSplit(HttpServletResponse response, @RequestParam String str1, @RequestParam String str2){ response.addHeader("Access-Control-Allow-Origin", "*"); String[] array = str1.split(str2); - return String.format("Result = %s", String.join(" ", array)); + return String.format(String.join(" ", array)); } @GetMapping("/uplow") @@ -29,9 +29,9 @@ public class UserController { return String.format(str1.toUpperCase() + str2.toLowerCase()); } - @GetMapping("/avg") - public String workAvarage(HttpServletResponse response, @RequestParam Integer num1, @RequestParam Integer num2){ + @GetMapping("/concat") + public String workCompare(HttpServletResponse response, @RequestParam String str1, @RequestParam String str2){ response.addHeader("Access-Control-Allow-Origin", "*"); - return String.format("Min = %s Max = %s Avg = %s", Math.min(num1, num2), Math.max(num1, num2), (num1 + num2) / 2); + return String.format(str1.concat(str2)); } } diff --git a/src/main/resources/frontend/spa-vue/src/pages/Index.vue b/src/main/resources/frontend/spa-vue/src/pages/Index.vue index 4c88dcf..62af864 100644 --- a/src/main/resources/frontend/spa-vue/src/pages/Index.vue +++ b/src/main/resources/frontend/spa-vue/src/pages/Index.vue @@ -16,8 +16,11 @@ export default{ }, methods:{ GetRepuest(){ - console.log("http://localhost:8080/" + this.action + "?" + this.str_1 + "&" + this.str_2) - fetch("http://localhost:8080/" + this.action + "?" + this.str_1 + "&" + this.str_2) + if (this.action.length == 0 || this.str_1.length == 0 || this.str_2.length == 0){ + console.warn("Invalid input to fetch!"); + } + console.log("http://localhost:8080/" + this.action + "?str1=" + this.str_1 + "&str2=" + this.str_2) + fetch("http://localhost:8080/" + this.action + "?str1=" + this.str_1 + "&str2=" + this.str_2) .then(res => res.text()) .then(res => { this.result = res; @@ -31,22 +34,24 @@ export default{
- Действие + Действие:
- Строка#01 + Строка№1:
- Строка#02 + Строка№2:
Вывод: - + +
+
+
-