public void save(Category category) { if (category.getId() == null) { entityManager.persist(category); } else { entityManager.merge(category); } result.redirectTo(CategoryController.class).search(); }
private Predicate[] getSearchPredicates(Root<Category> root, Category example) { CriteriaBuilder builder = this.entityManager.getCriteriaBuilder(); List<Predicate> predicatesList = new ArrayList<Predicate>(); String name = example.getName(); if (name != null && !"".equals(name)) { predicatesList.add(builder.like(root.<String>get("name"), '%' + name + '%')); } return predicatesList.toArray(new Predicate[predicatesList.size()]); }
public void delete(Category category) { entityManager.remove(entityManager.find(Category.class, category.getId())); result.redirectTo(CategoryController.class).search(); }
@Path("/category/edit/{category.id}") @Get public void edit(Category category) { result.include("category", entityManager.find(Category.class, category.getId())); }