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:
apeterlic
2022-10-13 07:02:48 +02:00
committed by GitHub
parent 684f9f01e9
commit 2aede0b5a5
10 changed files with 161 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}