Answer the question
In order to leave comments, you need to log in
How to return a list of objects in spring?
There is an entity Ship, it has 7 fields. Condition: return a list of all objects using a get request, by default there can be 3 entities on the page, or, if specified, then something else. Can you at least give an example of how to deal with this? I can return only 1 entity through model by putting it there. I don't know how many to put in...
Answer the question
In order to leave comments, you need to log in
@Repository
class ShipRepository {
@PersistenceContext
private EntityManager entityManager;
@Override
public List<Ship> findLimitedTo(int limit) {
return entityManager.createQuery("SELECT s FROM Ship s ORDER BY s.id",
Ship.class).setMaxResults(limit).getResultList();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question