package net.safedata.springboot.training.d02.s03;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Optional;

/**
 * A Spring {@link RestController} used to showcase the usages of the {@link RequestMapping} and of the {@link PathVariable}
 * Spring web annotations
 *
 * @author bogdan.solga
 */
@RestController
public class RequestMappingController {

    @RequestMapping(
            method = RequestMethod.GET,
            path = {
                    "/hello",
                    "/salut",
                    "bonjour"
            }
    )
    public String helloSpring() {
        return "Hello, Spring web! The date is " + new Date();
    }

    @RequestMapping(
            method = RequestMethod.GET,
            path = "/requestParams"
    )
    public String requestParamsIntro(@RequestParam(name = "color") String color,
                                     @RequestParam(required = false) String weight) {
        return "The color is '" + color + "', the weight is '" + Optional.ofNullable(weight)
                                                                         .orElse("N/A") + "'";
    }

    @RequestMapping(
            method = RequestMethod.GET,
            path = "/pathVariable/{first}/{second}"
    )
    public String pathVariableIntro(@PathVariable String first, @PathVariable String second) {
        return "The first path variable value is '" + first + "', the second is '" + second + "'";
    }
}

@@ -1596,22 +1596,76 @@
 rst,
- @PathVariable
+%0A                                    @PathVariable(required = false)
  Str

Split the path variable values