JAVA-8284: split or move spring-mvc-basics-2 module
This commit is contained in:
@@ -10,6 +10,4 @@ This module contains articles about Spring MVC
|
||||
- [Guide to Spring Email](https://www.baeldung.com/spring-email)
|
||||
- [Using ThymeLeaf and FreeMarker Emails Templates with Spring](https://www.baeldung.com/spring-email-templates)
|
||||
- [Request Method Not Supported (405) in Spring](https://www.baeldung.com/spring-request-method-not-supported-405)
|
||||
- [Spring @RequestParam Annotation](https://www.baeldung.com/spring-request-param)
|
||||
- [Spring @RequestParam vs @PathVariable Annotations](https://www.baeldung.com/spring-requestparam-vs-pathvariable)
|
||||
- More articles: [[<-- prev]](../spring-mvc-basics)[[more -->]](../spring-mvc-basics-3)
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.baeldung.spring.requestparam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
|
||||
@Controller
|
||||
public class RequestParamController {
|
||||
|
||||
@GetMapping("/api/foos")
|
||||
@ResponseBody
|
||||
public String getFoos(@RequestParam String id){
|
||||
return "ID: " + id;
|
||||
}
|
||||
|
||||
@PostMapping("/api/foos")
|
||||
@ResponseBody
|
||||
public String addFoo(@RequestParam(name = "id") String fooId, @RequestParam String name){
|
||||
return "ID: " + fooId;
|
||||
}
|
||||
|
||||
@GetMapping("/api/foos2")
|
||||
@ResponseBody
|
||||
public String getFoos2(@RequestParam(required = false) String id){
|
||||
return "ID: " + id;
|
||||
}
|
||||
|
||||
@GetMapping("/api/foosOptional")
|
||||
@ResponseBody
|
||||
public String getFoosOptional(@RequestParam Optional<String> id){
|
||||
return "ID: " + id.orElseGet(() -> "not provided");
|
||||
}
|
||||
|
||||
@GetMapping("/api/foos3")
|
||||
@ResponseBody
|
||||
public String getFoos3(@RequestParam(defaultValue = "test") String id){
|
||||
return "ID: " + id;
|
||||
}
|
||||
|
||||
@PostMapping("/api/foos1")
|
||||
@ResponseBody
|
||||
public String updateFoos(@RequestParam Map<String,String> allParams){
|
||||
return "Parameters are " + allParams.entrySet();
|
||||
}
|
||||
|
||||
@GetMapping("/api/foos4")
|
||||
@ResponseBody
|
||||
public String getFoos4(@RequestParam List<String> id){
|
||||
return "IDs are " + id;
|
||||
}
|
||||
|
||||
@GetMapping("/foos/{id}")
|
||||
@ResponseBody
|
||||
public String getFooById(@PathVariable String id){
|
||||
return "ID: " + id;
|
||||
}
|
||||
|
||||
@GetMapping("/foos")
|
||||
@ResponseBody
|
||||
public String getFooByIdUsingQueryParam(@RequestParam String id){
|
||||
return "ID: " + id;
|
||||
}
|
||||
|
||||
@GetMapping({"/myfoos/optional", "/myfoos/optional/{id}"})
|
||||
@ResponseBody
|
||||
public String getFooByOptionalId(@PathVariable(required = false) String id){
|
||||
return "ID: " + id;
|
||||
}
|
||||
|
||||
@GetMapping("/myfoos/optionalParam")
|
||||
@ResponseBody
|
||||
public String getFooByOptionalIdUsingQueryParam(@RequestParam(required = false) String id){
|
||||
return "ID: " + id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user