java - java.lang.InstantiationException 第二次
问题描述
我这里有一个小问题,需要我一些意见。
这是代码的和平
@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 类中提供了无 arg 构造函数?这里有什么问题?
@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;
}
解决方案
你的课是abstract
. 它不能被实例化。删除摘要,它应该可以工作。
推荐阅读
- python - 为什么格式化的字符串在{大括号}中包含变量或操作之前不需要进行类型转换?
- makefile - MinGW C 编译器“无法编译简单的测试程序”
- java - RestAssured,JSON:验证字段中是否缺少值
- node.js - mongoDB中的分组数据
- python - 在某些限制条件下随机化循环联赛的赛程
- gcc - W10 + Cygwin + gccV9.2 >>>-----> strtoflt128
- python - 如何向 exec 发送停止信号
- android - 离线期间的 Android GDPR 同意书行为
- istio - kiali 通过大使发送显示未知流量
- google-sheets-api - 使用 Google Sheet API 取消隐藏/显示列