Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
98dbc38f7e |
@ -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'
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
14
src/main/java/is/ulstu/ru/Application/MyController.java
Normal file
14
src/main/java/is/ulstu/ru/Application/MyController.java
Normal 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";
|
||||
}
|
||||
}
|
15
src/main/java/is/ulstu/ru/Application/WebConfiguration.java
Normal file
15
src/main/java/is/ulstu/ru/Application/WebConfiguration.java
Normal 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("*");
|
||||
}
|
||||
|
||||
}
|
@ -1 +1 @@
|
||||
|
||||
server.port=8080
|
10
src/main/resources/templates/index.html
Normal file
10
src/main/resources/templates/index.html
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user