Compare commits

...

1 Commits
lab2 ... master

Author SHA1 Message Date
Катя Ихонкина
0c0bd9c566 Коммит 2 2023-02-12 23:57:25 +04:00
7 changed files with 94 additions and 2 deletions

View File

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

View File

@ -0,0 +1,38 @@
package com.example.demo.Controllers;
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
class GController {
@GetMapping("/")
public String home(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "home";
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name, Model model) {
model.addAttribute("name", String.format("Hello %s!", name));
return "home";
}
@GetMapping("/sum")
public String doSum(@RequestParam int val1, @RequestParam int val2, Model model){
model.addAttribute("name", String.format("%s", val1+val2));
return "home";
}
@GetMapping("/sub")
public String doSub(@RequestParam int val1, @RequestParam int val2, Model model){
model.addAttribute("name", String.format("%s", val1-val2));
return "home";
}
@GetMapping("/hello2")
public String hello2(@RequestParam(value = "name", defaultValue = "World") String name,
@RequestParam(value = "day", defaultValue = "1") Integer day,
@RequestParam(value = "month", defaultValue = "January") String month, Model model) {
model.addAttribute("name", String.format("Hello %s!Your birthday is %s %s", name,day,month));
return "home";
}
}

View File

@ -14,8 +14,22 @@ public class DemoApplication {
SpringApplication.run(DemoApplication.class, args); SpringApplication.run(DemoApplication.class, args);
} }
@GetMapping("/hello") /*@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) { public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name); return String.format("Hello %s!", name);
} }
@GetMapping("/sum")
public Integer doSum(@RequestParam int val1, @RequestParam int val2){
return val1+val2;
}
@GetMapping("/sub")
public Integer doSub(@RequestParam int val1, @RequestParam int val2){
return val1-val2;
}
@GetMapping("/hello2")
public String hello2(@RequestParam(value = "name", defaultValue = "World") String name,
@RequestParam(value = "day", defaultValue = "1") Integer day,
@RequestParam(value = "month", defaultValue = "January") String month) {
return String.format("Hello %s!Your birthday is %s %s", name,day,month);
}*/
} }

View File

@ -0,0 +1,14 @@
package com.example.demo;
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 +0,0 @@

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Sarafan</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<p class="badge text-bg-primary " style="margin-top: 10%; margin-left: 10%; font-size: 64px" th:text="${name}"/>
</body>
</html>

View File

@ -0,0 +1,12 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>InsertTitleHere</title>
</head>
<body>
<h2>Hello ${name}!</h2>
</body>
</html>