POST请求-RequestBody方式
场景:json对象映射,数组对象提交接口开发
注解:@PostMapping = @RequestMapping(method = RequestMethod.POST)
代码:
VideoController:
@RestController
@RequestMapping("/api/v1/pub/video")
public class VideoController {
@Autowired
private VideoService videoService;
@PostMapping("save_video_chapter")
public JsonData saveVideoChapter(@RequestBody Video video){
System.out.println(video.toString());
return JsonData.buildSuccess(video);
}
}
Video:
public class Video implements Serializable {
private int id;
private String title;
private String summary;
private int price;
private String coverImg;
private Date createTime;
private List<Chapter> chapterList;
public List<Chapter> getChapterList() {
return chapterList;
}
public void setChapterList(List<Chapter> chapterList) {
this.chapterList = chapterList;
}
public Video(){}
public Video(int id,String title){
this.id=id;
this.title=title;
this.createTime=new Date();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getCoverImg() {
return coverImg;
}
public void setCoverImg(String coverImg) {
this.coverImg = coverImg;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
return "Video{" +
"id=" + id +
", title='" + title + '\'' +
", summary='" + summary + '\'' +
", price=" + price +
", coverImg='" + coverImg + '\'' +
", createTime=" + createTime +
", chapterList=" + chapterList +
'}';
}
}
Chapter:
public class Chapter {
private int id;
private int VideoId;
private String title;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getVideoId() {
return VideoId;
}
public void setVideoId(int videoId) {
VideoId = videoId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return "Chapter{" +
"id=" + id +
", VideoId=" + VideoId +
", title='" + title + '\'' +
'}';
}
}
效果截图:
-----------------------------------------------------------------------------------------------------------------------------------------------自学习