I tried it by referring to "Spring Quickstart Guide" on the official page of Spring. https://spring.io/quickstart
Generate to your liking on the official Project Generation Page.
Press the GENERATE button to download the project as a zip.
If there is no problem, the necessary libraries will be downloaded and the build will be done without permission.
When Spring Boot starts, it looks like this
Go to http: // localhost: 8080 /. I get an error because I haven't written the routing process yet.
Add routing to the main class in your project.
package com.pakhuncho.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
Relocate the modified application.
Access at http: // localhost: 8080 / hello.
Access with http: // localhost: 8080 / hello? Name = pakhuncho.
http: // localhost: 8080 / hello? name = Access with Pakupaku
package com.pakhuncho.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
@RequestMapping("/hello/{name}")
public String hello(@PathVariable String name) {
return String.format("Hello %s!", name);
}
}
Access with http: // localhost: 8080 / hello / Pakupaku
Recommended Posts