Compare commits

..

1 Commits

Author SHA1 Message Date
Denis
98dbc38f7e Сданная первая лаба 2023-02-27 14:23:26 +04:00
6 changed files with 62 additions and 4 deletions

View File

@ -14,6 +14,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

View File

@ -2,6 +2,8 @@ package is.ulstu.ru.Application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@ -13,9 +15,25 @@ public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
@GetMapping("/mult")
public int mult(@RequestParam(value = "firstDig") int firstDig, @RequestParam(value = "secondDig") int secondDig) {
return firstDig * secondDig;
}
@GetMapping("/sub")
public int sub(@RequestParam(value = "firstDig") int firstDig, @RequestParam(value = "secondDig") int secondDig) {
return firstDig - secondDig;
}
@GetMapping("/sum")
public int sum(@RequestParam(value = "firstDig") int firstDig, @RequestParam(value = "secondDig") int secondDig) {
return firstDig + secondDig;
}
@GetMapping("/div")
public int div(@RequestParam(value = "firstDig") int firstDig, @RequestParam(value = "secondDig") int secondDig) {
return firstDig / secondDig;
}
@GetMapping("/text")
public String div(@RequestParam(value = "text") String text) {
return text.toUpperCase();
}
}

View File

@ -0,0 +1,14 @@
package is.ulstu.ru.Application;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class MyController {
@GetMapping("/index")
public String index(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "index";
}
}

View File

@ -0,0 +1,15 @@
package is.ulstu.ru.Application;
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("*");
}
}

View File

@ -1 +1 @@
server.port=8080

View File

@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Spring Boot CLI + Javascript</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>