Skip to content

Instantly share code, notes, and snippets.

@koenighotze
Created September 29, 2015 21:41
Show Gist options
  • Save koenighotze/56e6bb6d9fafba7263ef to your computer and use it in GitHub Desktop.
Save koenighotze/56e6bb6d9fafba7263ef to your computer and use it in GitHub Desktop.
JAX-RS REST support in controller
@Named
@ApplicationScoped
@Path("hello")
public class HelloController {
@Inject
private Hello hello;
@PersistenceContext
private EntityManager em;
@GET
@Produces({APPLICATION_XML, APPLICATION_JSON})
public List<Hello> helloSoFar() {
CriteriaQuery<Hello> cq = this.em.getCriteriaBuilder().createQuery(Hello.class);
cq.select(cq.from(Hello.class));
return this.em.createQuery(cq).getResultList();
}
@POST
@Consumes({APPLICATION_XML, APPLICATION_JSON})
@Transactional
public void storeName(Hello hello) {
em.persist(hello);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment