--IntelliJ (free)
--Open the official page of Spring Initializr. ――Here, select the elements you need and create them. --When you have made your selection, click the Generate button. --A zip will be created in the location you specified, so unzip it.
--Open the folder you just unzipped. --Right-click on the build.gradle file and open it in IntelliJ.
--Without any modification to the SampleApplication class created in the early stages Create a new Controller class in the same directory as the SampleApplication class.
HelloController.java
@RestController
public class HelloController {
@GetMapping("/")
public String index() {
return "hello world";
}
@PostMapping("/")
public String index2() {
return "Hello";
}
--When you access "localhost: 8080", the GET method is called and The characters are displayed.
--Thymeleaf is not required. --When you make a change to the code, you have to press "■ (Stop)". Since it will be started multiple times, let's erase it one by one and then run "▶". --When you want to create RestAPI, not "@Controller" Let's add "@RestController".
Recommended Posts