This commit is contained in:
maxnes3 2023-02-19 23:51:57 +04:00
parent 4fb650e3d1
commit 04f358067f
2 changed files with 19 additions and 14 deletions

View File

@ -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));
}
}

View File

@ -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{
<Header></Header>
<main class="container" style="margin-top: 50pt;">
<div class="input-group mb-2 my-5">
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Действие</strong></span>
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Действие:</strong></span>
<input type="text" class="form-control" placeholder="Выберите действие" v-model="action">
</div>
<div class="input-group mb-2">
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Строка#01</strong></span>
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Строка1:</strong></span>
<input type="text" class="form-control" placeholder="Введите превую строку" v-model="str_1">
</div>
<div class="input-group mb-2">
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Строка#02</strong></span>
<span class="input-group-text bg-primary text-white" id="basic-addon1"><strong>Строка2:</strong></span>
<input type="text" class="form-control" placeholder="Введите вторую строку" v-model="str_2">
</div>
<div class="input-group mb-2">
<span class="input-group-text bg-success text-white" id="basic-addon1"><strong>Вывод:</strong></span>
<input type="text" class="form-control" placeholder="Выводит рузультат здесь" v-model="result">
<input type="text" class="form-control" placeholder="Выводит рузультат здесь" v-model="result" readonly>
</div>
<div class="mb-2 d-flex justify-content-center">
<button type="submit" class="btn btn-success" @click.prevent="GetRepuest"><strong>GET</strong></button>
</div>
<button type="submit" class="btn btn-success" @click.prevent="GetRepuest"><strong>GET</strong></button>
</main>
<Footer></Footer>
</template>