Commit 189c3e2c by Patryk Czarnik

odczyt produktów przez EM

parent 2ece785e
package sklep.controller;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sklep.model.Product;
@Controller
@RequestMapping("/alt2")
public class AlternatywneProdukty2 {
@Autowired
private EntityManager em;
@GetMapping("/products")
@ResponseBody
public String products() {
TypedQuery<Product> query = em.createNamedQuery("Product.findAll", Product.class);
List<Product> products = query.getResultList();
return products.stream().map(Product::getProductName).collect(Collectors.joining(", "));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment