我在这里遇到一些问题,需要我一些意见。
这是代码的和平
@XmlRootElement
public abstract class Article {
// quert params and name of xml elements
private String name;
private String author;
private String description;
private String picture_url;
private double price;
private int id;
public Article() {
}
public Article(String name, String author, String description, String picture_url, double price, int id) {
super();
this.name = name;
this.author = author;
this.description = description;
this.picture_url = picture_url;
this.price = price;
this.id = id;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
public String getDescription() {
return description;
}
public String getPicture_url() {
return picture_url;
}
public double getPrice() {
return price;
}
public int getId() {
return id;
}
}
我也有扩展文章的课程CD。问题是,当我尝试在REST应用程序中创建一个带有POST请求的新文章时,每次都抛出异常,但我在CD类中也提供了无参数构造函数?这里有什么问题?
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/articles")
public List<Article> gellAllItems(){
return new ArrayList<>(repo.get().values());
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/articles/{articleId}")
public Article get(@PathParam("articleId") int id) {
return repo.get(id);
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/articles")
public Article create(Article article) { // return a specific response with entity
repo.create(article);
return article;
}
答案 0 :(得分:3)
您的课程为abstract
。它无法实例化。删除摘要,它应该工作。