服务类 -
package org.sameer.learnSpringBoot.topic;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.stereotype.Service;
@Service
public class TopicService {
private List<Topic> topics = new ArrayList<>(Arrays.asList(new Topic("Spring", "Spring Framework", "Description for Spring"),
new Topic("Hibernate", "Hibernate Framework", "Description For Hibernate"),
new Topic("CoreJava", "Core Java Framework", "Description For CoreJava"),
new Topic("Servlets", "Servlets Framework", "Description for Servlets")));
public List<Topic> getAllTopic() {
return topics;
}
public Topic getTopic(String id) {
return topics.stream().filter(t -> t.getId().equals(id)).findFirst().get();
}
public void addTopic(Topic topic) {
topics.add(topic);
}
}
控制器类 -
@RequestMapping(method = RequestMethod.POST ,value="/topics")
public void addTopic(@RequestBody Topic topic) {
topicService.addTopic(topic);
}
模型类主题 -
package org.sameer.learnSpringBoot.topic;
public class Topic {
private String id;
private String name;
private String description;
public Topic() {
}
public Topic(String id, String name, String description) {
super();
this.id = id;
this.name = name;
this.description = description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
我无法使用chrome发布的POSTMAN插件。 enter image description here
在Satacktrace中获得同样的东西 -
2018-02-17 15:57:59.841 WARN 4328 --- [nio-8080-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public void org.sameer.learnSpringBoot.topic.TopicController.addTopic(org.sameer.learnSpringBoot.topic.Topic)
2018-02-17 15:58:08.501 WARN 4328 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public void org.sameer.learnSpringBoot.topic.TopicController.addTopic(org.sameer.learnSpringBoot.topic.Topic)
我正在学习Spring Boot。我正在尝试HTML将值放到我的主题页面 任何人都可以让我知道我在这里失踪了什么???工作精细 STS -4.7.1 JRE - 1.8