From c8fe76f814ba473a4690a7c685a3cc2656271172 Mon Sep 17 00:00:00 2001 From: dimazhelovanov Date: Mon, 20 Feb 2023 21:24:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=84=D1=80=D0=BE=D0=BD=D1=82=D0=B5=D0=BD=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/ulstu/is/myapp/MyappApplication.java | 37 +++++++++++++++++-- .../ru/ulstu/is/myapp/WebConfiguration.java | 14 +++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ru/ulstu/is/myapp/WebConfiguration.java diff --git a/src/main/java/ru/ulstu/is/myapp/MyappApplication.java b/src/main/java/ru/ulstu/is/myapp/MyappApplication.java index 02c46fb..1b6c49a 100644 --- a/src/main/java/ru/ulstu/is/myapp/MyappApplication.java +++ b/src/main/java/ru/ulstu/is/myapp/MyappApplication.java @@ -2,9 +2,9 @@ package ru.ulstu.is.myapp; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.Date; @SpringBootApplication @@ -14,10 +14,41 @@ public class MyappApplication { public static void main(String[] args) { SpringApplication.run(MyappApplication.class, args); } + @GetMapping("/hello") public String hello(@RequestParam(value = "name", defaultValue = "World") String name) { return String.format("Hello %s!", name); } + @CrossOrigin + @GetMapping(value = "/add") + public Integer doSum(@RequestParam(value = "a", defaultValue = "0") int a, + @RequestParam(value = "b", defaultValue = "0") int b){ + return a + b; + } + @GetMapping("/sub") + public Integer doSub(@RequestParam(value = "a", defaultValue = "0") int a, + @RequestParam(value = "b", defaultValue = "0") int b){ + return a - b; + } + @GetMapping("/mul") + public Integer doMul(@RequestParam(value = "a", defaultValue = "0") int a, + @RequestParam(value = "b", defaultValue = "0") int b){ + return a * b; + } + @GetMapping("/del") + public Integer doDel(@RequestParam(value = "a", defaultValue = "0") int a, + @RequestParam(value = "b", defaultValue = "1") int b){ + return a / b; + } + @GetMapping("/mu") + public String len(@RequestParam(value = "word", defaultValue = "") String name){ + return String.format("Длина слова " + name + " " + len(name)); + } + @GetMapping("/de") + public String root(){ + return new Date().toString(); + } + diff --git a/src/main/java/ru/ulstu/is/myapp/WebConfiguration.java b/src/main/java/ru/ulstu/is/myapp/WebConfiguration.java new file mode 100644 index 0000000..143b5fb --- /dev/null +++ b/src/main/java/ru/ulstu/is/myapp/WebConfiguration.java @@ -0,0 +1,14 @@ +package ru.ulstu.is.myapp; + +import org.springframework.beans.factory.annotation.Configurable; +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("*"); + } +} \ No newline at end of file