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