该应用程序适用于生成的方法和类,但我想获得与特定idChapitre匹配的文章列表。我在浏览器上收到“HTTP状态404 - 未找到”。
这是外观类,我在其中放入了findByIdChapitre方法:
@Stateless
@Path("articles")
public class ArticleFacadeREST extends AbstractFacade<Article> {
@PersistenceContext(unitName = "PNC-BackendPU")
private EntityManager em;
public ArticleFacadeREST() {
super(Article.class);
}
@GET
@Path("bychapitre/{idChapitre}")
@Produces({"application/json"})
public List<Article> findByIdChapitre(@PathParam("idChapitre") Chapitre idChapitre) {
Query q = em.createNamedQuery("Article.findByIdChapitre");
q.setParameter("idChapitre", idChapitre);
return q.getResultList();
}
...
}
和我的文章课:
@Entity
@Table(name = "article")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Article.findAll", query = "SELECT a FROM Article a"),
@NamedQuery(name = "Article.findByIdArticle", query = "SELECT a FROM Article a WHERE a.idArticle = :idArticle"),
@NamedQuery(name = "Article.findByIdChapitre", query = "SELECT a FROM Article a WHERE a.idChapitre = :idChapitre"),
@NamedQuery(name = "Article.findByCodeArticle", query = "SELECT a FROM Article a WHERE a.codeArticle = :codeArticle")})
public class Article implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id_article", nullable = false)
private Integer idArticle;
@Lob
@Size(max = 65535)
@Column(name = "nom_article", length = 65535)
private String nomArticle;
@Size(max = 20)
@Column(name = "code_article", length = 20)
private String codeArticle;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idArticle")
private List<Littera> litteraList;
@JoinColumn(name = "id_chapitre", referencedColumnName = "id_chapitre", nullable = false)
@ManyToOne(optional = false)
private Chapitre idChapitre;
public Article() {
}
public Article(Integer idArticle) {
this.idArticle = idArticle;
}
Getters and setters
} 然后我的chapitreclass: ....
@Entity
@Table(name = "chapitre")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Chapitre.findAll", query = "SELECT c FROM Chapitre c"),
@NamedQuery(name = "Chapitre.findByIdChapitre", query = "SELECT c FROM Chapitre c WHERE c.idChapitre = :idChapitre"),
@NamedQuery(name = "Chapitre.findByIdSection", query = "SELECT c FROM Chapitre c WHERE c.idSection = :idSection"),
@NamedQuery(name = "Chapitre.findByCodeChapitre", query = "SELECT c FROM Chapitre c WHERE c.codeChapitre = :codeChapitre")})
public class Chapitre implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id_chapitre", nullable = false)
private Integer idChapitre;
@Lob
@Size(max = 65535)
@Column(name = "nom_chapitre", length = 65535)
private String nomChapitre;
@Size(max = 20)
@Column(name = "code_chapitre", length = 20)
private String codeChapitre;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idChapitre")
private List<Dossier> dossierList;
@JoinColumn(name = "id_section", referencedColumnName = "id_section", nullable = false)
@ManyToOne(optional = false)
private Section idSection;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idChapitre")
private List<Article> articleList;
public Chapitre() {
}
public Chapitre(Integer idChapitre) {
this.idChapitre = idChapitre;
}
Getters and setters
}