Added Spring Boot web service
This commit is contained in:
20
src/main/java/MTGClone/MTGSpringApp.java
Normal file
20
src/main/java/MTGClone/MTGSpringApp.java
Normal file
@ -0,0 +1,20 @@
|
||||
package MTGClone;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MTGSpringApp extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(MTGSpringApp.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MTGSpringApp.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
23
src/main/java/MTGClone/controller/HelloController.java
Normal file
23
src/main/java/MTGClone/controller/HelloController.java
Normal file
@ -0,0 +1,23 @@
|
||||
package MTGClone.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
public class HelloController {
|
||||
@GetMapping({"/", "/hello"})
|
||||
public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) {
|
||||
model.addAttribute("name", name);
|
||||
return "hello";
|
||||
}
|
||||
|
||||
@PostMapping({"/greet"})
|
||||
public String greet(@RequestParam("name") String name, ModelMap modelMap) {
|
||||
modelMap.put("name", name);
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
2
src/main/resources/application.properties
Normal file
2
src/main/resources/application.properties
Normal file
@ -0,0 +1,2 @@
|
||||
spring.mvc.view.prefix=/WEB-INF/jsp/
|
||||
spring.mvc.view.suffix=.jsp
|
||||
16
src/main/webapp/WEB-INF/jsp/hello.jsp
Normal file
16
src/main/webapp/WEB-INF/jsp/hello.jsp
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Hello ${name}!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2 class="hello-title">Hello ${name}!</h2>
|
||||
<form action="/greet" method="post">
|
||||
<label for="fname">First name:</label>
|
||||
<input type="text" id="name" name="name"><br><br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user