Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0c0bd9c566 |
@ -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'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
src/main/java/com/example/demo/Controllers/GController.java
Normal file
38
src/main/java/com/example/demo/Controllers/GController.java
Normal 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";
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
14
src/main/java/com/example/demo/WebConfiguration.java
Normal file
14
src/main/java/com/example/demo/WebConfiguration.java
Normal 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("*");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
|
|
14
src/main/resources/templates/home.html
Normal file
14
src/main/resources/templates/home.html
Normal 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>
|
12
src/main/webapp/WEB-INF/jsp/NewFile.jsp
Normal file
12
src/main/webapp/WEB-INF/jsp/NewFile.jsp
Normal 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>
|
Loading…
Reference in New Issue
Block a user