Created
September 29, 2015 21:41
-
-
Save koenighotze/56e6bb6d9fafba7263ef to your computer and use it in GitHub Desktop.
JAX-RS REST support in controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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