Add Send Array as Part of x-www-form-urlencoded (#12808)
* Add Send Array as Part of x-www-form-urlencoded * Add README.md
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootRest3Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootRest3Application.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.xwwwformurlencoded;
|
||||
|
||||
class Course {
|
||||
|
||||
private String name;
|
||||
private int hours;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getHours() {
|
||||
return hours;
|
||||
}
|
||||
|
||||
public void setHours(int hours) {
|
||||
this.hours = hours;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.xwwwformurlencoded;
|
||||
|
||||
class StudentComplex {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private Course[] courses;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Course[] getCourses() {
|
||||
return courses;
|
||||
}
|
||||
|
||||
public void setCourses(Course[] courses) {
|
||||
this.courses = courses;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.xwwwformurlencoded;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/students")
|
||||
public class StudentController {
|
||||
|
||||
@PostMapping(path = "/simple",
|
||||
consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE })
|
||||
public ResponseEntity<StudentSimple> createStudentSimple(StudentSimple student) {
|
||||
return ResponseEntity.ok(student);
|
||||
}
|
||||
|
||||
@PostMapping(path = "/complex",
|
||||
consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE })
|
||||
public ResponseEntity<StudentComplex> createStudentComplex(StudentComplex student) {
|
||||
return ResponseEntity.ok(student);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.xwwwformurlencoded;
|
||||
|
||||
class StudentSimple {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String[] courses;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String[] getCourses() {
|
||||
return courses;
|
||||
}
|
||||
|
||||
public void setCourses(String[] courses) {
|
||||
this.courses = courses;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user