Search code examples
javasqljdbi

SQL Objects API - All rows?


I am having some trouble getting back all the rows in my table - Below you will see code for how I return one row (which works), and map it to a user object.

controller code

@GET
@Timed
@Path("/retrieve/{id}")
public User retrieveUserRecord(@PathParam("id") int id)
{
    User result = dao.findUserById(id);
    return result;
}

DAO code:

//Get User process record by id.
@SqlQuery("select * from users where ID = :id")
@Mapper(UserMapper.class)
User findUserById(@Bind("id") int id);

Thats great and all - But now I need to write another query that will return all User records in a list.

Thanks in advance for any help!


Solution

  • This should return all the users

     @SqlQuery("select * from users")
     @Mapper(UserMapper.class)
     List<User> fetchUsers();